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 473682293 : section_hasher::equal (section *old, const char *new_name)
213 : {
214 473682293 : return strcmp (old->named.name, new_name) == 0;
215 : }
216 :
217 : hashval_t
218 338639895 : section_hasher::hash (section *old)
219 : {
220 338639895 : 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 1181700 : get_unnamed_section (unsigned int flags, void (*callback) (const char *),
251 : const char *data)
252 : {
253 1181700 : section *sect;
254 :
255 1181700 : sect = ggc_alloc<section> ();
256 1181700 : sect->unnamed.common.flags = flags | SECTION_UNNAMED;
257 1181700 : sect->unnamed.callback = callback;
258 1181700 : sect->unnamed.data = data;
259 1181700 : sect->unnamed.next = unnamed_sections;
260 :
261 1181700 : unnamed_sections = sect;
262 1181700 : return sect;
263 : }
264 :
265 : /* Return a SECTION_NOSWITCH section with the given fields. */
266 :
267 : static section *
268 1181700 : get_noswitch_section (unsigned int flags, noswitch_section_callback callback)
269 : {
270 1181700 : section *sect;
271 :
272 0 : sect = ggc_alloc<section> ();
273 1181700 : sect->noswitch.common.flags = flags | SECTION_NOSWITCH;
274 1181700 : sect->noswitch.callback = callback;
275 :
276 1181700 : 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 72926969 : get_section (const char *name, unsigned int flags, tree decl,
290 : bool not_existing)
291 : {
292 72926969 : section *sect, **slot;
293 :
294 72926969 : slot = section_htab->find_slot_with_hash (name, htab_hash_string (name),
295 : INSERT);
296 72926969 : flags |= SECTION_NAMED;
297 72926969 : if (decl != nullptr
298 70862901 : && DECL_P (decl)
299 143789870 : && lookup_attribute ("retain", DECL_ATTRIBUTES (decl)))
300 458 : flags |= SECTION_RETAIN;
301 72926969 : if (*slot == NULL)
302 : {
303 3545279 : sect = ggc_alloc<section> ();
304 3545279 : sect->named.common.flags = flags;
305 3545279 : sect->named.name = ggc_strdup (name);
306 3545279 : sect->named.decl = decl;
307 3545279 : *slot = sect;
308 : }
309 : else
310 : {
311 69381690 : if (not_existing)
312 0 : internal_error ("section already exists: %qs", name);
313 :
314 69381690 : 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 69381690 : 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 69381690 : 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 10478364 : use_object_blocks_p (void)
384 : {
385 10478364 : 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 70683050 : get_named_section (tree decl, const char *name, int reloc)
458 : {
459 70683050 : unsigned int flags;
460 :
461 70683050 : if (name == NULL)
462 : {
463 62985408 : gcc_assert (decl && DECL_P (decl) && DECL_SECTION_NAME (decl));
464 62985408 : name = DECL_SECTION_NAME (decl);
465 : }
466 :
467 70683050 : flags = targetm.section_type_flags (decl, name, reloc);
468 70683050 : return get_section (name, flags, decl);
469 : }
470 :
471 : /* Worker for resolve_unique_section. */
472 :
473 : static bool
474 1862269 : set_implicit_section (struct symtab_node *n, void *data ATTRIBUTE_UNUSED)
475 : {
476 1862269 : n->implicit_section = true;
477 1862269 : return false;
478 : }
479 :
480 : /* If required, set DECL_SECTION_NAME to a unique name. */
481 :
482 : void
483 7544592 : resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED,
484 : int flag_function_or_data_sections)
485 : {
486 7544592 : if (DECL_SECTION_NAME (decl) == NULL
487 4664817 : && targetm_common.have_named_sections
488 12209409 : && (flag_function_or_data_sections
489 2974853 : || lookup_attribute ("retain", DECL_ATTRIBUTES (decl))
490 2974735 : || DECL_COMDAT_GROUP (decl)))
491 : {
492 1818796 : targetm.asm_out.unique_section (decl, reloc);
493 1818796 : if (DECL_SECTION_NAME (decl))
494 1818796 : symtab_node::get (decl)->call_for_symbol_and_aliases
495 1818796 : (set_implicit_section, NULL, true);
496 : }
497 7544592 : }
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 85120773 : hot_function_section (tree decl)
535 : {
536 85120773 : if (decl != NULL_TREE
537 85120773 : && DECL_SECTION_NAME (decl) != NULL
538 145126875 : && targetm_common.have_named_sections)
539 60006102 : return get_named_section (decl, NULL, 0);
540 : else
541 25114671 : 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 7692221 : get_named_text_section (tree decl,
555 : const char *text_section_name,
556 : const char *named_section_suffix)
557 : {
558 7692221 : if (decl && DECL_SECTION_NAME (decl))
559 : {
560 6710190 : 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 6710190 : else if (symtab_node::get (decl)->implicit_section)
576 : {
577 6710169 : const char *name;
578 :
579 : /* Do not try to split gnu_linkonce functions. This gets somewhat
580 : slipperly. */
581 6710169 : if (DECL_COMDAT_GROUP (decl) && !HAVE_COMDAT_GROUP)
582 : return NULL;
583 6710169 : name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
584 6710169 : name = targetm.strip_name_encoding (name);
585 6710169 : return get_named_section (decl, ACONCAT ((text_section_name, ".",
586 6710169 : name, NULL)), 0);
587 : }
588 : else
589 : return NULL;
590 : }
591 982031 : return get_named_section (decl, text_section_name, 0);
592 : }
593 :
594 : /* Choose named function section based on its frequency. */
595 :
596 : section *
597 92812973 : 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 92812973 : if (!flag_reorder_functions
609 90317898 : || !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 90317898 : 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 1622416 : if (!in_lto_p
621 39415 : || !cgraph_node::get (decl)->tp_first_run
622 1622426 : || !opt_for_fn (decl, flag_profile_reorder_functions))
623 1622406 : return get_named_text_section (decl, ".text.startup", NULL);
624 : else
625 : return NULL;
626 : }
627 :
628 : /* Similarly for exit. */
629 88695482 : if (exit && freq != NODE_FREQUENCY_UNLIKELY_EXECUTED)
630 4186 : return get_named_text_section (decl, ".text.exit", NULL);
631 :
632 : /* Group cold functions together, similarly for hot code. */
633 88691296 : switch (freq)
634 : {
635 6064920 : case NODE_FREQUENCY_UNLIKELY_EXECUTED:
636 6064920 : 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 92812973 : function_section_1 (tree decl, bool force_cold)
655 : {
656 92812973 : section *section = NULL;
657 92812973 : enum node_frequency freq = NODE_FREQUENCY_NORMAL;
658 92812973 : bool startup = false, exit = false;
659 :
660 92812973 : if (decl)
661 : {
662 92812973 : struct cgraph_node *node = cgraph_node::get (decl);
663 :
664 92812973 : if (node)
665 : {
666 92812973 : freq = node->frequency;
667 92812973 : startup = node->only_called_at_startup;
668 92812973 : exit = node->only_called_at_exit;
669 : }
670 : }
671 92812973 : if (force_cold)
672 5865780 : 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 92812973 : if (targetm.asm_out.function_section)
691 92812973 : section = targetm.asm_out.function_section (decl, freq, startup, exit);
692 92812973 : if (section)
693 : return section;
694 85120773 : 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 3773112 : 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 3773112 : return function_section_1 (decl,
712 3773112 : 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 88899386 : current_function_section (void)
720 : {
721 88899386 : 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 140475 : unlikely_text_section (void)
728 : {
729 140475 : 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 639506 : default_function_rodata_section (tree decl, bool relocatable)
758 : {
759 639506 : const char* sname;
760 639506 : unsigned int flags;
761 :
762 639506 : flags = 0;
763 :
764 639506 : if (relocatable)
765 : {
766 : sname = ".data.rel.ro.local";
767 : flags = (SECTION_WRITE | SECTION_RELRO);
768 : }
769 : else
770 639506 : sname = ".rodata";
771 :
772 639506 : if (decl && DECL_SECTION_NAME (decl))
773 : {
774 124813 : const char *name = DECL_SECTION_NAME (decl);
775 :
776 124813 : if (DECL_COMDAT_GROUP (decl) && HAVE_COMDAT_GROUP)
777 : {
778 38967 : const char *dot;
779 38967 : size_t len;
780 38967 : char* rname;
781 :
782 38967 : dot = strchr (name + 1, '.');
783 38967 : if (!dot)
784 0 : dot = name;
785 38967 : len = strlen (dot) + strlen (sname) + 1;
786 38967 : rname = (char *) alloca (len);
787 :
788 38967 : strcpy (rname, sname);
789 38967 : strcat (rname, dot);
790 38967 : 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 85846 : else if (DECL_COMDAT_GROUP (decl)
795 85846 : && 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 85842 : else if (flag_function_sections && flag_data_sections
820 171688 : && startswith (name, ".text."))
821 : {
822 85842 : size_t len = strlen (name) + 1;
823 85842 : char *rname = (char *) alloca (len + strlen (sname) - 5);
824 :
825 85842 : memcpy (rname, sname, strlen (sname));
826 85842 : memcpy (rname + strlen (sname), name + 5, len - 5);
827 85842 : return get_section (rname, flags, decl);
828 : }
829 : }
830 :
831 514697 : if (relocatable)
832 0 : return get_section (sname, flags, decl);
833 : else
834 514697 : 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 624592 : function_mergeable_rodata_prefix (void)
851 : {
852 624592 : section *s = targetm.asm_out.function_rodata_section (current_function_decl,
853 : false);
854 624592 : if (SECTION_STYLE (s) == SECTION_NAMED)
855 116487 : return s->named.name;
856 : else
857 508105 : return targetm.asm_out.mergeable_rodata_prefix;
858 : }
859 :
860 : /* Return the section to use for string merging. */
861 :
862 : static section *
863 1257976 : mergeable_string_section (tree decl ATTRIBUTE_UNUSED,
864 : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED,
865 : unsigned int flags ATTRIBUTE_UNUSED)
866 : {
867 1257976 : HOST_WIDE_INT len;
868 :
869 1257976 : if (HAVE_GAS_SHF_MERGE && flag_merge_constants
870 1063787 : && TREE_CODE (decl) == STRING_CST
871 1063787 : && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
872 1063787 : && align <= MAX_MERGEABLE_BITSIZE
873 1063787 : && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0
874 2321626 : && TREE_STRING_LENGTH (decl) == len)
875 : {
876 416972 : scalar_int_mode mode;
877 416972 : unsigned int modesize;
878 416972 : const char *str;
879 416972 : HOST_WIDE_INT i;
880 416972 : int j, unit;
881 416972 : const char *prefix = function_mergeable_rodata_prefix ();
882 416972 : char *name = (char *) alloca (strlen (prefix) + 30);
883 :
884 416972 : mode = SCALAR_INT_TYPE_MODE (TREE_TYPE (TREE_TYPE (decl)));
885 416972 : modesize = GET_MODE_BITSIZE (mode);
886 416972 : if (modesize >= 8 && modesize <= MAX_MERGEABLE_BITSIZE
887 416972 : && (modesize & (modesize - 1)) == 0)
888 : {
889 416972 : if (align < modesize)
890 : align = modesize;
891 :
892 416972 : str = TREE_STRING_POINTER (decl);
893 416972 : unit = GET_MODE_SIZE (mode);
894 :
895 : /* Check for embedded NUL characters. */
896 116632896 : for (i = 0; i < len; i += unit)
897 : {
898 116989315 : for (j = 0; j < unit; j++)
899 116609357 : if (str[i + j] != '\0')
900 : break;
901 116595882 : if (j == unit)
902 : break;
903 : }
904 416972 : if (i == len - unit || (unit == 1 && i == len))
905 : {
906 413200 : sprintf (name, "%s.str%d.%d", prefix,
907 413200 : modesize / BITS_PER_UNIT, (int) (align / BITS_PER_UNIT));
908 413200 : flags |= (modesize / BITS_PER_UNIT) | SECTION_MERGE | SECTION_STRINGS;
909 413200 : return get_section (name, flags, NULL);
910 : }
911 : }
912 : }
913 :
914 844776 : return readonly_data_section;
915 : }
916 :
917 : /* Return the section to use for constant merging. */
918 :
919 : section *
920 251783 : mergeable_constant_section (unsigned HOST_WIDE_INT size_bits,
921 : unsigned HOST_WIDE_INT align,
922 : unsigned int flags)
923 : {
924 251783 : unsigned HOST_WIDE_INT newsize;
925 251783 : newsize = HOST_WIDE_INT_1U << ceil_log2 (size_bits);
926 251783 : if (HAVE_GAS_SHF_MERGE && flag_merge_constants
927 212033 : && newsize <= MAX_MERGEABLE_BITSIZE
928 212033 : && align >= 8
929 207620 : && align <= newsize
930 207620 : && (align & (align - 1)) == 0)
931 : {
932 207620 : const char *prefix = function_mergeable_rodata_prefix ();
933 207620 : char *name = (char *) alloca (strlen (prefix) + 30);
934 :
935 207620 : sprintf (name, "%s.cst%d", prefix, (int) (newsize / BITS_PER_UNIT));
936 207620 : flags |= (newsize / BITS_PER_UNIT) | SECTION_MERGE;
937 207620 : return get_section (name, flags, NULL);
938 : }
939 44163 : 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 481 : mergeable_constant_section (tree size_bits,
947 : unsigned HOST_WIDE_INT align,
948 : unsigned int flags)
949 : {
950 481 : if (!size_bits || !tree_fits_uhwi_p (size_bits))
951 0 : return readonly_data_section;
952 481 : 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 251302 : 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 251302 : if (mode == BLKmode || mode == VOIDmode)
966 0 : return readonly_data_section;
967 251302 : unsigned HOST_WIDE_INT size;
968 502604 : if (!GET_MODE_BITSIZE (mode).is_constant (&size))
969 : return readonly_data_section;
970 251302 : 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 12607756 : 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 12607132 : if (name[0] == '%' || name[0] == '#')
984 624 : name++;
985 12607756 : 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 2921796 : set_user_assembler_name (tree decl, const char *name)
993 : {
994 2921796 : char *starred = (char *) alloca (strlen (name) + 2);
995 2921796 : starred[0] = '*';
996 2921796 : strcpy (starred + 1, name);
997 2921796 : symtab->change_decl_assembler_name (decl, get_identifier (starred));
998 2921796 : SET_DECL_RTL (decl, NULL_RTX);
999 2921796 : }
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 167750 : decode_reg_name_and_count (const char *asmspec, int *pnregs)
1013 : {
1014 : /* Presume just one register is clobbered. */
1015 167750 : *pnregs = 1;
1016 :
1017 167750 : if (asmspec != 0)
1018 : {
1019 167750 : int i;
1020 :
1021 : /* Get rid of confusing prefixes. */
1022 167750 : asmspec = strip_reg_name (asmspec);
1023 :
1024 : /* Allow a decimal number as a "register name". */
1025 167750 : if (ISDIGIT (asmspec[0]))
1026 : {
1027 72 : char *pend;
1028 72 : errno = 0;
1029 72 : unsigned long j = strtoul (asmspec, &pend, 10);
1030 72 : if (*pend == '\0')
1031 : {
1032 66 : static_assert (FIRST_PSEUDO_REGISTER <= INT_MAX, "");
1033 66 : if (errno != ERANGE
1034 63 : && j < FIRST_PSEUDO_REGISTER
1035 48 : && reg_names[j][0])
1036 66 : return j;
1037 : else
1038 : return -2;
1039 : }
1040 : }
1041 :
1042 12543077 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1043 12440006 : if (reg_names[i][0]
1044 24880012 : && ! 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 7740943 : for (i = 0; i < (int) ARRAY_SIZE (table); i++)
1072 7660747 : if (table[i].name[0]
1073 7660747 : && ! strcmp (asmspec, table[i].name)
1074 22875 : && reg_names[table[i].number][0])
1075 : return table[i].number;
1076 : }
1077 : #endif /* ADDITIONAL_REGISTER_NAMES */
1078 :
1079 80196 : if (!strcmp (asmspec, "redzone"))
1080 : return -5;
1081 :
1082 80192 : 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 85297 : decode_reg_name (const char *name)
1096 : {
1097 85297 : int count;
1098 85297 : 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 6524457 : 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 11215412 : return ((!TREE_READONLY (decl) || DECL_COMMON (decl) || named)
1110 6548091 : && (DECL_INITIAL (decl) == NULL
1111 : /* In LTO we have no errors in program; error_mark_node is used
1112 : to mark offlined constructors. */
1113 687460 : || (DECL_INITIAL (decl) == error_mark_node
1114 4 : && !in_lto_p)
1115 687456 : || (flag_zero_initialized_in_bss
1116 687398 : && 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 40486 : && !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 6003846 : align_variable (tree decl, bool dont_output_data)
1128 : {
1129 6003846 : 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 6003846 : && 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 6003846 : if (! DECL_USER_ALIGN (decl))
1149 : {
1150 : #ifdef DATA_ABI_ALIGNMENT
1151 5874366 : unsigned int data_abi_align
1152 5874366 : = DATA_ABI_ALIGNMENT (TREE_TYPE (decl), align);
1153 : /* For backwards compatibility, don't assume the ABI alignment for
1154 : TLS variables. */
1155 5874458 : 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 5874366 : if (decl_binds_to_current_def_p (decl)
1165 5874366 : && !DECL_VIRTUAL_P (decl))
1166 : {
1167 : #ifdef DATA_ALIGNMENT
1168 5253030 : 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 5253098 : if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1172 : align = data_align;
1173 : #endif
1174 5253030 : 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 5253030 : && (in_lto_p || DECL_INITIAL (decl) != error_mark_node))
1178 : {
1179 3294054 : unsigned int const_align
1180 3294054 : = targetm.constant_alignment (DECL_INITIAL (decl), align);
1181 : /* Don't increase alignment too much for TLS variables - TLS
1182 : space is too precious. */
1183 3294060 : 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 6003846 : SET_DECL_ALIGN (decl, align);
1192 6003846 : }
1193 :
1194 : /* Return DECL_ALIGN (decl), possibly increased for optimization purposes
1195 : beyond what align_variable returned. */
1196 :
1197 : static unsigned int
1198 5870686 : get_variable_align (tree decl)
1199 : {
1200 5870686 : unsigned int align = DECL_ALIGN (decl);
1201 :
1202 : /* For user aligned vars or static vars align_variable already did
1203 : everything. */
1204 5870686 : if (DECL_USER_ALIGN (decl) || !TREE_PUBLIC (decl))
1205 : return align;
1206 :
1207 : #ifdef DATA_ABI_ALIGNMENT
1208 2900417 : if (DECL_THREAD_LOCAL_P (decl))
1209 6260 : 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 2900417 : 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 601572 : 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 601593 : if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD)
1224 : align = data_align;
1225 : #endif
1226 601572 : 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 601572 : && (in_lto_p || DECL_INITIAL (decl) != error_mark_node))
1230 : {
1231 586571 : unsigned int const_align
1232 586571 : = targetm.constant_alignment (DECL_INITIAL (decl), align);
1233 : /* Don't increase alignment too much for TLS variables - TLS space
1234 : is too precious. */
1235 586576 : 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 4534499 : compute_reloc_for_var (tree decl)
1249 : {
1250 4534499 : int reloc;
1251 :
1252 4534499 : if (DECL_INITIAL (decl) == error_mark_node)
1253 1148122 : reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0;
1254 4534497 : else if (DECL_INITIAL (decl))
1255 3386377 : reloc = compute_reloc_for_constant (DECL_INITIAL (decl));
1256 : else
1257 : reloc = 0;
1258 :
1259 4534499 : 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 4535923 : get_variable_section (tree decl, bool prefer_noswitch_p)
1268 : {
1269 4535923 : addr_space_t as = ADDR_SPACE_GENERIC;
1270 4535923 : int reloc;
1271 4535923 : varpool_node *vnode = varpool_node::get (decl);
1272 4535923 : if (vnode)
1273 : {
1274 4535908 : vnode = vnode->ultimate_alias_target ();
1275 4535908 : decl = vnode->decl;
1276 : }
1277 :
1278 4535923 : if (TREE_TYPE (decl) != error_mark_node)
1279 4535923 : as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1280 :
1281 : /* We need the constructor to figure out reloc flag. */
1282 4535923 : if (vnode)
1283 4535908 : vnode->get_constructor ();
1284 :
1285 4535923 : if (DECL_COMMON (decl)
1286 4535923 : && !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 4534499 : reloc = compute_reloc_for_var (decl);
1300 :
1301 4534499 : resolve_unique_section (decl, reloc, flag_data_sections);
1302 4534499 : if (IN_NAMED_SECTION (decl))
1303 : {
1304 2975612 : section *sect = get_named_section (decl, NULL, reloc);
1305 :
1306 2975612 : if ((sect->common.flags & SECTION_BSS)
1307 2975612 : && !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 1558887 : if (ADDR_SPACE_GENERIC_P (as)
1323 1558881 : && !DECL_THREAD_LOCAL_P (decl)
1324 1555205 : && !DECL_NOINIT_P (decl)
1325 1555205 : && !(prefer_noswitch_p && targetm.have_switchable_bss_sections)
1326 3114092 : && bss_initializer_p (decl))
1327 : {
1328 1157780 : if (!TREE_PUBLIC (decl)
1329 1157988 : && !((flag_sanitize & SANITIZE_ADDRESS)
1330 208 : && asan_protect_global (decl)))
1331 159453 : return lcomm_section;
1332 998327 : if (bss_noswitch_section)
1333 : return bss_noswitch_section;
1334 : }
1335 :
1336 401107 : return targetm.asm_out.select_section (decl, reloc,
1337 802214 : 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 37763546 : ultimate_transparent_alias_target (tree *alias)
1435 : {
1436 37763546 : tree target = *alias;
1437 :
1438 37763546 : 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 37763546 : 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 8837568 : make_decl_rtl (tree decl)
1478 : {
1479 8837568 : const char *name = 0;
1480 8837568 : int reg_number;
1481 8837568 : tree id;
1482 8837568 : rtx x;
1483 :
1484 : /* Check that we are not being given an automatic variable. */
1485 8837568 : 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 8837568 : 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 8837568 : 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 8837568 : if (DECL_RTL_SET_P (decl))
1502 : {
1503 : /* If the old RTL had the wrong mode, fix the mode. */
1504 13366 : x = DECL_RTL (decl);
1505 13366 : if (GET_MODE (x) != DECL_MODE (decl))
1506 0 : SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0));
1507 :
1508 13366 : 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 13297 : 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 13297 : if (MEM_P (x)
1524 13297 : && GET_CODE (XEXP (x, 0)) == SYMBOL_REF
1525 26594 : && 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 8824202 : if (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
1534 : {
1535 6850 : SET_DECL_RTL (decl, output_constant_def (DECL_INITIAL (decl), 1));
1536 6850 : return;
1537 : }
1538 :
1539 8817352 : id = DECL_ASSEMBLER_NAME (decl);
1540 8817352 : name = IDENTIFIER_POINTER (id);
1541 :
1542 8752036 : if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL
1543 12006605 : && DECL_REGISTER (decl))
1544 : {
1545 13 : error ("register name not specified for %q+D", decl);
1546 : }
1547 8817339 : else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
1548 : {
1549 1233 : const char *asmspec = name+1;
1550 1233 : machine_mode mode = DECL_MODE (decl);
1551 1233 : reg_number = decode_reg_name (asmspec);
1552 : /* First detect errors in declaring global registers. */
1553 1233 : if (reg_number == -1)
1554 0 : error ("register name not specified for %q+D", decl);
1555 1233 : else if (reg_number < 0)
1556 28 : error ("invalid register name for %q+D", decl);
1557 1205 : else if (mode == BLKmode)
1558 5 : error ("data type of %q+D isn%'t suitable for a register",
1559 : decl);
1560 1200 : 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 1198 : 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 1198 : 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 1195 : else if (reg_number != HARD_FRAME_POINTER_REGNUM
1570 1189 : && (reg_number == FRAME_POINTER_REGNUM
1571 : #ifdef RETURN_ADDRESS_POINTER_REGNUM
1572 : || reg_number == RETURN_ADDRESS_POINTER_REGNUM
1573 : #endif
1574 1189 : || reg_number == ARG_POINTER_REGNUM)
1575 1200 : && 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 1190 : int nregs;
1582 :
1583 1190 : 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 1190 : 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 1190 : SET_DECL_RTL (decl, gen_raw_REG (mode, reg_number));
1599 1190 : ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number;
1600 1190 : REG_USERVAR_P (DECL_RTL (decl)) = 1;
1601 :
1602 1190 : 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 8816119 : if (VAR_P (decl)
1648 3234717 : && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
1649 3234717 : && DECL_SECTION_NAME (decl) != NULL
1650 1436985 : && DECL_INITIAL (decl) == NULL_TREE
1651 8816248 : && DECL_COMMON (decl))
1652 0 : DECL_COMMON (decl) = 0;
1653 :
1654 : /* Variables can't be both common and weak. */
1655 8816119 : if (VAR_P (decl) && DECL_WEAK (decl))
1656 338062 : DECL_COMMON (decl) = 0;
1657 :
1658 8816119 : 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 8816119 : machine_mode address_mode = Pmode;
1663 8816119 : if (TREE_TYPE (decl) != error_mark_node)
1664 : {
1665 8816119 : addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (decl));
1666 8816119 : address_mode = targetm.addr_space.address_mode (as);
1667 : }
1668 8816119 : x = gen_rtx_SYMBOL_REF (address_mode, name);
1669 : }
1670 8816119 : SYMBOL_REF_WEAK (x) = DECL_WEAK (decl);
1671 8816119 : SET_SYMBOL_REF_DECL (x, decl);
1672 :
1673 8816119 : x = gen_rtx_MEM (DECL_MODE (decl), x);
1674 8816119 : if (TREE_CODE (decl) != FUNCTION_DECL)
1675 3234717 : set_mem_attributes (x, decl, 1);
1676 8816119 : 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 8816119 : 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 47376 : make_decl_rtl_for_debug (tree decl)
1691 : {
1692 47376 : unsigned int save_aliasing_flag;
1693 47376 : rtx rtl;
1694 :
1695 47376 : 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 47376 : save_aliasing_flag = flag_strict_aliasing;
1705 47376 : flag_strict_aliasing = 0;
1706 :
1707 47376 : 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 47376 : SET_DECL_RTL (decl, NULL);
1711 :
1712 47376 : flag_strict_aliasing = save_aliasing_flag;
1713 47376 : return rtl;
1714 : }
1715 :
1716 : /* Output a string of literal assembler code
1717 : for an `asm' keyword used between functions. */
1718 :
1719 : void
1720 12453 : assemble_asm (tree asm_str)
1721 : {
1722 12453 : const char *p;
1723 :
1724 12453 : if (TREE_CODE (asm_str) != ASM_EXPR)
1725 : {
1726 12388 : app_enable ();
1727 12388 : if (TREE_CODE (asm_str) == ADDR_EXPR)
1728 0 : asm_str = TREE_OPERAND (asm_str, 0);
1729 :
1730 12388 : p = TREE_STRING_POINTER (asm_str);
1731 24741 : 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 12453 : }
1887 :
1888 : /* Write the address of the entity given by SYMBOL to SEC. */
1889 : void
1890 26230 : assemble_addr_to_section (rtx symbol, section *sec)
1891 : {
1892 26230 : switch_to_section (sec);
1893 26639 : assemble_align (POINTER_SIZE);
1894 27048 : assemble_integer (symbol, POINTER_SIZE_UNITS, POINTER_SIZE, 1);
1895 26230 : }
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 128625291 : notice_global_symbol (tree decl)
1978 : {
1979 249377 : const char **t = &first_global_object_name;
1980 :
1981 128625291 : if (first_global_object_name
1982 86878918 : || !TREE_PUBLIC (decl)
1983 85972063 : || DECL_EXTERNAL (decl)
1984 23459889 : || !DECL_NAME (decl)
1985 23459811 : || (VAR_P (decl) && DECL_HARD_REGISTER (decl))
1986 152085062 : || (TREE_CODE (decl) != FUNCTION_DECL
1987 16180015 : && (!VAR_P (decl)
1988 16180015 : || (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 23459475 : if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib)
1996 23210098 : t = &weak_global_object_name;
1997 :
1998 23459475 : if (!*t)
1999 : {
2000 288377 : tree id = DECL_ASSEMBLER_NAME (decl);
2001 288377 : ultimate_transparent_alias_target (&id);
2002 288377 : *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 1537734 : decide_function_section (tree decl)
2013 : {
2014 1537734 : first_function_block_is_cold = false;
2015 :
2016 1537734 : if (DECL_SECTION_NAME (decl))
2017 : {
2018 8161 : 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 8161 : first_function_block_is_cold = (node
2022 8161 : && node->frequency
2023 8161 : == NODE_FREQUENCY_UNLIKELY_EXECUTED);
2024 : }
2025 :
2026 1537734 : in_cold_section_p = first_function_block_is_cold;
2027 1537734 : }
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 1611048 : get_fnname_from_decl (tree decl)
2033 : {
2034 1611048 : rtx x = DECL_RTL (decl);
2035 1611048 : gcc_assert (MEM_P (x));
2036 1611048 : x = XEXP (x, 0);
2037 1611048 : gcc_assert (GET_CODE (x) == SYMBOL_REF);
2038 1611048 : 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 1602414 : assemble_function_label_raw (FILE *file, const char *name)
2046 : {
2047 1602414 : ASM_OUTPUT_LABEL (file, name);
2048 1602414 : assemble_function_label_final ();
2049 1602414 : }
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 1602414 : assemble_function_label_final (void)
2056 : {
2057 1602414 : if ((flag_sanitize & SANITIZE_ADDRESS)
2058 : /* Notify ASAN only about the first function label. */
2059 6898 : && (in_cold_section_p == first_function_block_is_cold)
2060 : /* Do not notify ASAN when called from, e.g., code_end (). */
2061 6718 : && cfun)
2062 6718 : asan_function_start ();
2063 1602414 : }
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 1533029 : assemble_start_function (tree decl, const char *fnname)
2072 : {
2073 1533029 : int align;
2074 1533029 : char tmp_label[100];
2075 1533029 : bool hot_label_written = false;
2076 :
2077 1533029 : if (crtl->has_bb_partition)
2078 : {
2079 65691 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno);
2080 65691 : crtl->subsections.hot_section_label = ggc_strdup (tmp_label);
2081 65691 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno);
2082 65691 : crtl->subsections.cold_section_label = ggc_strdup (tmp_label);
2083 65691 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno);
2084 65691 : crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label);
2085 65691 : ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno);
2086 65691 : crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label);
2087 65691 : const_labelno++;
2088 65691 : cold_function_name = NULL_TREE;
2089 : }
2090 : else
2091 : {
2092 1467338 : crtl->subsections.hot_section_label = NULL;
2093 1467338 : crtl->subsections.cold_section_label = NULL;
2094 1467338 : crtl->subsections.hot_section_end_label = NULL;
2095 1467338 : crtl->subsections.cold_section_end_label = NULL;
2096 : }
2097 :
2098 : /* The following code does not need preprocessing in the assembler. */
2099 :
2100 1533029 : app_disable ();
2101 :
2102 1533029 : if (CONSTANT_POOL_BEFORE_FUNCTION)
2103 1533029 : output_constant_pool (fnname, decl);
2104 :
2105 1533029 : 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 1533029 : if (crtl->has_bb_partition)
2113 : {
2114 65691 : first_function_block_is_cold = false;
2115 :
2116 65691 : switch_to_section (unlikely_text_section ());
2117 65691 : assemble_align (align);
2118 65691 : 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 65691 : if (!cfun->is_thunk
2124 65691 : && 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 65691 : 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 1533029 : switch_to_section (function_section (decl), decl);
2139 1533029 : if (crtl->has_bb_partition && !hot_label_written)
2140 65691 : 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 1533029 : 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 1533029 : if (flag_min_function_alignment)
2147 0 : align = MAX (align, floor_log2 (flag_min_function_alignment));
2148 :
2149 1533029 : if (align > 0)
2150 : {
2151 173171 : 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 1533029 : if (! DECL_USER_ALIGN (decl)
2158 1532995 : && align_functions.levels[0].log > align
2159 2473015 : && optimize_function_for_speed_p (cfun))
2160 : {
2161 : #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
2162 921342 : int align_log = align_functions.levels[0].log;
2163 : #endif
2164 921342 : int max_skip = align_functions.levels[0].maxskip;
2165 921342 : 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 921342 : ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file, align_log, max_skip);
2171 921342 : if (max_skip == align_functions.levels[0].maxskip)
2172 921341 : 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 1533029 : if (!DECL_IGNORED_P (decl))
2185 1525959 : (*debug_hooks->begin_function) (decl);
2186 :
2187 : /* Make function name accessible from other files, if appropriate. */
2188 :
2189 1533029 : if (TREE_PUBLIC (decl))
2190 : {
2191 1250438 : notice_global_symbol (decl);
2192 :
2193 1250438 : globalize_decl (decl);
2194 :
2195 1250438 : maybe_assemble_visibility (decl);
2196 : }
2197 :
2198 1533029 : if (DECL_PRESERVE_P (decl))
2199 5163 : targetm.asm_out.mark_decl_preserved (fnname);
2200 :
2201 1533029 : unsigned short patch_area_size = crtl->patch_area_size;
2202 1533029 : unsigned short patch_area_entry = crtl->patch_area_entry;
2203 :
2204 : /* Emit the patching area before the entry label, if any. */
2205 1533029 : 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 1533029 : 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 1533029 : if (patch_area_size > patch_area_entry)
2219 55 : targetm.asm_out.print_patchable_function_entry (asm_out_file,
2220 55 : patch_area_size
2221 55 : - patch_area_entry,
2222 : patch_area_entry == 0);
2223 :
2224 1533029 : if (lookup_attribute ("no_split_stack", DECL_ATTRIBUTES (decl)))
2225 2458 : saw_no_split_stack = true;
2226 1533029 : }
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 1533029 : 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 1533029 : if (crtl->has_bb_partition)
2237 65691 : switch_to_section (function_section (decl));
2238 1533029 : ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
2239 : #endif
2240 1533029 : 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 1533029 : if (crtl->has_bb_partition)
2248 : {
2249 65691 : section *save_text_section;
2250 :
2251 65691 : save_text_section = in_section;
2252 65691 : switch_to_section (unlikely_text_section ());
2253 : #ifdef ASM_DECLARE_COLD_FUNCTION_SIZE
2254 65691 : if (cold_function_name != NULL_TREE)
2255 65691 : ASM_DECLARE_COLD_FUNCTION_SIZE (asm_out_file,
2256 : IDENTIFIER_POINTER (cold_function_name),
2257 : decl);
2258 : #endif
2259 65691 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label);
2260 65691 : if (first_function_block_is_cold)
2261 0 : switch_to_section (text_section);
2262 : else
2263 65691 : switch_to_section (function_section (decl));
2264 65691 : ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label);
2265 65691 : switch_to_section (save_text_section);
2266 : }
2267 1533029 : }
2268 :
2269 : /* Assemble code to leave SIZE bytes of zeros. */
2270 :
2271 : void
2272 1058661 : assemble_zeros (unsigned HOST_WIDE_INT size)
2273 : {
2274 : /* Do no output if -fsyntax-only. */
2275 1058661 : 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 1058661 : 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 1058661 : if (size > 0)
2290 987042 : ASM_OUTPUT_SKIP (asm_out_file, size);
2291 : }
2292 :
2293 : /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
2294 :
2295 : void
2296 394272 : assemble_align (unsigned int align)
2297 : {
2298 394272 : if (align > BITS_PER_UNIT)
2299 : {
2300 333888 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2301 : }
2302 394272 : }
2303 :
2304 : /* Assemble a string constant with the specified C string as contents. */
2305 :
2306 : void
2307 33805770 : assemble_string (const char *p, int size)
2308 : {
2309 33805770 : 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 33805770 : int maximum = 16384;
2320 : #else
2321 : int maximum = 2000;
2322 : #endif
2323 :
2324 : /* If the string is very long, split it up. */
2325 :
2326 67606678 : while (pos < size)
2327 : {
2328 33800908 : int thissize = size - pos;
2329 33800908 : if (thissize > maximum)
2330 : thissize = maximum;
2331 :
2332 33800908 : ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
2333 :
2334 33800908 : pos += thissize;
2335 33800908 : p += thissize;
2336 : }
2337 33805770 : }
2338 :
2339 :
2340 : /* A noswitch_section_callback for lcomm_section. */
2341 :
2342 : static bool
2343 159449 : 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 159449 : unsigned int align = symtab_node::get (decl)->definition_alignment ();
2350 159449 : ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name,
2351 : size, align);
2352 159449 : 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 773756 : 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 773756 : ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
2373 : get_variable_align (decl));
2374 773756 : 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 934567 : assemble_noswitch_variable (tree decl, const char *name, section *sect,
2422 : unsigned int align)
2423 : {
2424 934567 : unsigned HOST_WIDE_INT size, rounded;
2425 :
2426 934567 : size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2427 934567 : rounded = size;
2428 :
2429 934567 : if ((flag_sanitize & SANITIZE_ADDRESS) && asan_protect_global (decl))
2430 2006 : 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 934567 : 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 934567 : rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
2440 934567 : rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2441 934567 : * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
2442 :
2443 934567 : if (!sect->noswitch.callback (decl, name, size, rounded)
2444 934567 : && (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 934567 : }
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 1929607 : 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 1929607 : last_assemble_variable_decl = decl;
2460 1929607 : 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 1929607 : if (!dont_output_data)
2467 : {
2468 : /* Caller is supposed to use varpool_get_constructor when it wants
2469 : to output the body. */
2470 1925977 : gcc_assert (!in_lto_p || DECL_INITIAL (decl) != error_mark_node);
2471 1925977 : if (DECL_INITIAL (decl)
2472 1913697 : && DECL_INITIAL (decl) != error_mark_node
2473 3839672 : && !initializer_zerop (DECL_INITIAL (decl)))
2474 : /* Output the actual data. */
2475 3660694 : output_constant (DECL_INITIAL (decl),
2476 1830347 : tree_to_uhwi (DECL_SIZE_UNIT (decl)),
2477 : get_variable_align (decl),
2478 : false, merge_strings);
2479 : else
2480 : /* Leave space for it. */
2481 95630 : 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 1925977 : if (in_section
2485 1925977 : && (in_section->common.flags & SECTION_MERGE)
2486 106 : && tree_fits_uhwi_p (DECL_SIZE_UNIT (decl))
2487 1925977 : && ((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 1925977 : targetm.asm_out.decl_end ();
2496 : }
2497 1929607 : }
2498 :
2499 : /* Write out assembly for the variable DECL, which is not defined in
2500 : the current translation unit. */
2501 : void
2502 296109 : assemble_undefined_decl (tree decl)
2503 : {
2504 296109 : const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
2505 296109 : targetm.asm_out.assemble_undefined_decl (asm_out_file, name, decl);
2506 296109 : }
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 2868756 : assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED,
2520 : int at_end ATTRIBUTE_UNUSED, int dont_output_data)
2521 : {
2522 2868756 : const char *name;
2523 2868756 : rtx decl_rtl, symbol;
2524 2868756 : section *sect;
2525 2868756 : unsigned int align;
2526 2868756 : bool asan_protected = false;
2527 :
2528 : /* This function is supposed to handle VARIABLES. Ensure we have one. */
2529 2868756 : gcc_assert (VAR_P (decl));
2530 :
2531 : /* Emulated TLS had better not get this far. */
2532 2868756 : gcc_checking_assert (targetm.have_tls || !DECL_THREAD_LOCAL_P (decl));
2533 :
2534 2868756 : 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 2868756 : if (DECL_EXTERNAL (decl))
2541 : return;
2542 :
2543 : /* Do nothing for global register variables. */
2544 2866319 : 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 2866319 : 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 2866319 : 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 2866318 : if (TREE_ASM_WRITTEN (decl))
2572 : return;
2573 :
2574 : /* Make sure targetm.encode_section_info is invoked before we set
2575 : ASM_WRITTEN. */
2576 2866318 : decl_rtl = DECL_RTL (decl);
2577 :
2578 2866318 : TREE_ASM_WRITTEN (decl) = 1;
2579 :
2580 : /* Do no output if -fsyntax-only. */
2581 2866318 : if (flag_syntax_only)
2582 : return;
2583 :
2584 2866318 : if (! dont_output_data
2585 2866318 : && ! 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 2866316 : gcc_assert (MEM_P (decl_rtl));
2592 2866316 : gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF);
2593 2866316 : 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 2866316 : if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
2598 : {
2599 2142 : tree decl = SYMBOL_REF_DECL (symbol);
2600 2142 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
2601 1460 : output_constant_def_contents (symbol);
2602 : return;
2603 : }
2604 :
2605 2864174 : app_disable ();
2606 :
2607 2864174 : name = XSTR (symbol, 0);
2608 2864174 : if (TREE_PUBLIC (decl) && DECL_NAME (decl))
2609 1423756 : notice_global_symbol (decl);
2610 :
2611 : /* Compute the alignment of this data. */
2612 :
2613 2864174 : align_variable (decl, dont_output_data);
2614 :
2615 2864174 : if ((flag_sanitize & SANITIZE_ADDRESS)
2616 2864174 : && asan_protect_global (decl))
2617 : {
2618 2678 : asan_protected = true;
2619 2678 : SET_DECL_ALIGN (decl, MAX (DECL_ALIGN (decl),
2620 : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT));
2621 : }
2622 :
2623 2864174 : set_mem_align (decl_rtl, DECL_ALIGN (decl));
2624 :
2625 2864174 : align = get_variable_align (decl);
2626 :
2627 2864174 : if (TREE_PUBLIC (decl))
2628 1424311 : maybe_assemble_visibility (decl);
2629 :
2630 2864174 : 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 2864174 : sect = get_variable_section (decl, false);
2635 2864174 : if (TREE_PUBLIC (decl)
2636 1424311 : && (sect->common.flags & SECTION_COMMON) == 0)
2637 1422949 : globalize_decl (decl);
2638 :
2639 : /* Output any data that we will need to use the address of. */
2640 2864174 : if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node)
2641 1939599 : output_addressed_constants (DECL_INITIAL (decl), 0);
2642 :
2643 : /* dbxout.cc needs to know this. */
2644 2864174 : 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 2864174 : 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 2864174 : else if (SECTION_STYLE (sect) == SECTION_NOSWITCH)
2656 934567 : assemble_noswitch_variable (decl, name, sect, align);
2657 : else
2658 : {
2659 : /* Special-case handling of vtv comdat sections. */
2660 1929607 : if (SECTION_STYLE (sect) == SECTION_NAMED
2661 1539642 : && (strcmp (sect->named.name, ".vtable_map_vars") == 0))
2662 3 : handle_vtv_comdat_section (sect, decl);
2663 : else
2664 1929604 : switch_to_section (sect, decl);
2665 1929607 : if (align > BITS_PER_UNIT)
2666 1842921 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2667 1929607 : assemble_variable_contents (decl, name, dont_output_data,
2668 1929607 : (sect->common.flags & SECTION_MERGE)
2669 106 : && (sect->common.flags & SECTION_STRINGS));
2670 1929607 : if (asan_protected)
2671 : {
2672 1618 : unsigned HOST_WIDE_INT int size
2673 1618 : = tree_to_uhwi (DECL_SIZE_UNIT (decl));
2674 3064 : 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 1835050 : incorporeal_function_p (tree decl)
2740 : {
2741 1835050 : if (TREE_CODE (decl) == FUNCTION_DECL && fndecl_built_in_p (decl))
2742 : {
2743 206831 : const char *name;
2744 :
2745 206831 : if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL
2746 206831 : && ALLOCA_FUNCTION_CODE_P (DECL_FUNCTION_CODE (decl)))
2747 : return true;
2748 :
2749 206826 : 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 206826 : 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 1847093 : assemble_external_real (tree decl)
2762 : {
2763 1847093 : rtx rtl = DECL_RTL (decl);
2764 :
2765 1847093 : if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
2766 1847093 : && !SYMBOL_REF_USED (XEXP (rtl, 0))
2767 3682143 : && !incorporeal_function_p (decl))
2768 : {
2769 : /* Some systems do require some output. */
2770 1835045 : SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
2771 1835045 : ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
2772 : }
2773 1847093 : }
2774 : #endif
2775 :
2776 : void
2777 243525 : process_pending_assemble_externals (void)
2778 : {
2779 : #ifdef ASM_OUTPUT_EXTERNAL
2780 243525 : tree list;
2781 2090618 : for (list = pending_assemble_externals; list; list = TREE_CHAIN (list))
2782 1847093 : assemble_external_real (TREE_VALUE (list));
2783 :
2784 271226 : for (rtx list = pending_libcall_symbols; list; list = XEXP (list, 1))
2785 : {
2786 27701 : rtx symbol = XEXP (list, 0);
2787 27701 : const char *name = targetm.strip_name_encoding (XSTR (symbol, 0));
2788 27701 : tree id = get_identifier (name);
2789 27701 : if (TREE_SYMBOL_REFERENCED (id))
2790 27632 : targetm.asm_out.external_libcall (symbol);
2791 : }
2792 :
2793 243525 : pending_assemble_externals = 0;
2794 243525 : pending_assemble_externals_processed = true;
2795 243525 : pending_libcall_symbols = NULL_RTX;
2796 487050 : delete pending_assemble_externals_set;
2797 243525 : pending_assemble_externals_set = nullptr;
2798 : #endif
2799 243525 : }
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 42169708 : 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 42169708 : 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 42169708 : 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 18315109 : if (TARGET_SUPPORTS_WEAK
2837 18315109 : && 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 12932 : && !TREE_STATIC (decl)
2844 5239 : && lookup_attribute ("weak", DECL_ATTRIBUTES (decl))
2845 18319885 : && value_member (decl, weak_decls) == NULL_TREE)
2846 1004 : weak_decls = tree_cons (NULL, decl, weak_decls);
2847 :
2848 : #ifdef ASM_OUTPUT_EXTERNAL
2849 18315109 : if (pending_assemble_externals_processed)
2850 : {
2851 0 : assemble_external_real (decl);
2852 0 : return;
2853 : }
2854 :
2855 18315109 : if (! pending_assemble_externals_set->add (decl))
2856 1847139 : 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 204747 : assemble_external_libcall (rtx fun)
2865 : {
2866 : /* Declare library function name external when first used, if nec. */
2867 204747 : if (! SYMBOL_REF_USED (fun))
2868 : {
2869 : #ifdef ASM_OUTPUT_EXTERNAL
2870 27711 : gcc_assert (!pending_assemble_externals_processed);
2871 : #endif
2872 27711 : 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 27711 : const char *name = targetm.strip_name_encoding (XSTR (fun, 0));
2878 27711 : get_identifier (name);
2879 27711 : pending_libcall_symbols = gen_rtx_EXPR_LIST (VOIDmode, fun,
2880 : pending_libcall_symbols);
2881 : }
2882 204747 : }
2883 :
2884 : /* Assemble a label named NAME. */
2885 :
2886 : void
2887 1290843 : assemble_label (FILE *file, const char *name)
2888 : {
2889 1290843 : ASM_OUTPUT_LABEL (file, name);
2890 1290843 : }
2891 :
2892 : /* Set the symbol_referenced flag for ID. */
2893 : void
2894 35480895 : mark_referenced (tree id)
2895 : {
2896 35480895 : TREE_SYMBOL_REFERENCED (id) = 1;
2897 35480895 : }
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 489322581 : assemble_name_raw (FILE *file, const char *name)
2933 : {
2934 489322581 : if (name[0] == '*')
2935 453520975 : fputs (&name[1], file);
2936 : else
2937 35801606 : ASM_OUTPUT_LABELREF (file, name);
2938 489322581 : }
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 412193186 : assemble_name_resolve (const char *name)
2946 : {
2947 412193186 : const char *real_name = targetm.strip_name_encoding (name);
2948 412193186 : tree id = maybe_get_identifier (real_name);
2949 :
2950 412193186 : if (id)
2951 : {
2952 35480895 : tree id_orig = id;
2953 :
2954 35480895 : mark_referenced (id);
2955 35480895 : ultimate_transparent_alias_target (&id);
2956 35480895 : if (id != id_orig)
2957 0 : name = IDENTIFIER_POINTER (id);
2958 35480895 : gcc_assert (!IDENTIFIER_TRANSPARENT_ALIAS (id));
2959 : }
2960 :
2961 412193186 : 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 283389730 : assemble_name (FILE *file, const char *name)
2971 : {
2972 283389730 : assemble_name_raw (file, assemble_name_resolve (name));
2973 283389730 : }
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 15292578 : min_align (unsigned int a, unsigned int b)
3067 : {
3068 15292578 : 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 468569700 : integer_asm_op (int size, int aligned_p)
3081 : {
3082 468569700 : struct asm_int_op *ops;
3083 :
3084 468569700 : if (aligned_p)
3085 : ops = &targetm.asm_out.aligned_op;
3086 : else
3087 454052145 : ops = &targetm.asm_out.unaligned_op;
3088 :
3089 468569700 : switch (size)
3090 : {
3091 238303460 : case 1:
3092 238303460 : return targetm.asm_out.byte_op;
3093 24110200 : case 2:
3094 24110200 : return ops->hi;
3095 0 : case 3:
3096 0 : return ops->psi;
3097 166378600 : case 4:
3098 166378600 : return ops->si;
3099 0 : case 5:
3100 0 : case 6:
3101 0 : case 7:
3102 0 : return ops->pdi;
3103 39750199 : case 8:
3104 39750199 : 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 26594 : case 16:
3114 26594 : 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 14247363 : assemble_integer_with_op (const char *op, rtx x)
3125 : {
3126 14247363 : fputs (op, asm_out_file);
3127 14247363 : output_addr_const (asm_out_file, x);
3128 14247363 : fputc ('\n', asm_out_file);
3129 14247363 : }
3130 :
3131 : /* The default implementation of the asm_out.integer target hook. */
3132 :
3133 : bool
3134 14546347 : default_assemble_integer (rtx x ATTRIBUTE_UNUSED,
3135 : unsigned int size ATTRIBUTE_UNUSED,
3136 : int aligned_p ATTRIBUTE_UNUSED)
3137 : {
3138 14546347 : 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 19535554 : if (size > UNITS_PER_WORD && size > POINTER_SIZE_UNITS)
3142 : return false;
3143 14247363 : 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 14546347 : assemble_integer (rtx x, unsigned int size, unsigned int align, int force)
3153 : {
3154 14546347 : int aligned_p;
3155 :
3156 14546347 : aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT));
3157 :
3158 : /* See if the target hook can handle this kind of object. */
3159 14546347 : 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 298984 : if (size > 1)
3165 : {
3166 298984 : machine_mode omode, imode;
3167 298984 : unsigned int subalign;
3168 298984 : unsigned int subsize, i;
3169 298984 : enum mode_class mclass;
3170 :
3171 574040 : subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1;
3172 298984 : subalign = MIN (align, subsize * BITS_PER_UNIT);
3173 298984 : if (GET_CODE (x) == CONST_FIXED)
3174 0 : mclass = GET_MODE_CLASS (GET_MODE (x));
3175 : else
3176 : mclass = MODE_INT;
3177 :
3178 298984 : omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0).require ();
3179 298984 : imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0).require ();
3180 :
3181 900834 : for (i = 0; i < size; i += subsize)
3182 : {
3183 601850 : rtx partial = simplify_subreg (omode, x, imode, i);
3184 601850 : if (!partial || !assemble_integer (partial, subsize, subalign, 0))
3185 : break;
3186 : }
3187 298984 : if (i == size)
3188 14546347 : 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 810897 : assemble_real (REAL_VALUE_TYPE d, scalar_float_mode mode, unsigned int align,
3206 : bool reverse)
3207 : {
3208 810897 : long data[4] = {0, 0, 0, 0};
3209 810897 : int bitsize, nelts, nunits, units_per;
3210 810897 : 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 810897 : nunits = GET_MODE_SIZE (mode);
3225 810897 : bitsize = nunits * BITS_PER_UNIT;
3226 810897 : nelts = CEIL (bitsize, 32);
3227 810897 : units_per = 32 / BITS_PER_UNIT;
3228 :
3229 810897 : real_to_target (data, &d, mode);
3230 :
3231 : /* Put out the first word with the specified alignment. */
3232 810897 : unsigned int chunk_nunits = MIN (nunits, units_per);
3233 810897 : if (reverse && nunits == 2)
3234 1 : elt = flip_storage_order (HImode, gen_int_mode (data[nelts - 1], HImode));
3235 810896 : else if (reverse && nunits >= 4)
3236 72 : elt = flip_storage_order (SImode, gen_int_mode (data[nelts - 1], SImode));
3237 : else
3238 810824 : elt = GEN_INT (sext_hwi (data[0], chunk_nunits * BITS_PER_UNIT));
3239 810897 : assemble_integer (elt, chunk_nunits, align, 1);
3240 810897 : nunits -= chunk_nunits;
3241 :
3242 : /* Subsequent words need only 32-bit alignment. */
3243 810897 : align = min_align (align, 32);
3244 :
3245 1221077 : for (int i = 1; i < nelts; i++)
3246 : {
3247 410180 : chunk_nunits = MIN (nunits, units_per);
3248 410180 : if (reverse)
3249 18 : elt = flip_storage_order (SImode,
3250 18 : gen_int_mode (data[nelts - 1 - i], SImode));
3251 : else
3252 410162 : elt = GEN_INT (sext_hwi (data[i], chunk_nunits * BITS_PER_UNIT));
3253 410180 : assemble_integer (elt, chunk_nunits, align, 1);
3254 410180 : nunits -= chunk_nunits;
3255 : }
3256 810897 : }
3257 :
3258 : /* Given an expression EXP with a constant value,
3259 : reduce it to the sum of an assembler symbol and an integer.
3260 : Store them both in the structure *VALUE.
3261 : EXP must be reducible. */
3262 :
3263 : class addr_const {
3264 : public:
3265 : rtx base;
3266 : poly_int64 offset;
3267 : };
3268 :
3269 : static void
3270 30094 : decode_addr_const (tree exp, class addr_const *value)
3271 : {
3272 30094 : tree target = TREE_OPERAND (exp, 0);
3273 30094 : poly_int64 offset = 0;
3274 30546 : rtx x;
3275 :
3276 30998 : while (1)
3277 : {
3278 30546 : poly_int64 bytepos;
3279 30546 : if (TREE_CODE (target) == COMPONENT_REF
3280 30546 : && poly_int_tree_p (byte_position (TREE_OPERAND (target, 1)),
3281 : &bytepos))
3282 : {
3283 438 : offset += bytepos;
3284 438 : target = TREE_OPERAND (target, 0);
3285 : }
3286 30108 : else if (TREE_CODE (target) == ARRAY_REF
3287 30108 : || TREE_CODE (target) == ARRAY_RANGE_REF)
3288 : {
3289 : /* Truncate big offset. */
3290 14 : offset
3291 14 : += (TREE_INT_CST_LOW (TYPE_SIZE_UNIT (TREE_TYPE (target)))
3292 28 : * wi::to_poly_widest (TREE_OPERAND (target, 1)).force_shwi ());
3293 14 : target = TREE_OPERAND (target, 0);
3294 : }
3295 30094 : else if (TREE_CODE (target) == MEM_REF
3296 30094 : && TREE_CODE (TREE_OPERAND (target, 0)) == ADDR_EXPR)
3297 : {
3298 0 : offset += mem_ref_offset (target).force_shwi ();
3299 0 : target = TREE_OPERAND (TREE_OPERAND (target, 0), 0);
3300 : }
3301 30094 : else if (INDIRECT_REF_P (target)
3302 0 : && TREE_CODE (TREE_OPERAND (target, 0)) == NOP_EXPR
3303 30094 : && TREE_CODE (TREE_OPERAND (TREE_OPERAND (target, 0), 0))
3304 : == ADDR_EXPR)
3305 0 : target = TREE_OPERAND (TREE_OPERAND (TREE_OPERAND (target, 0), 0), 0);
3306 : else
3307 : break;
3308 452 : }
3309 :
3310 30094 : switch (TREE_CODE (target))
3311 : {
3312 29992 : case VAR_DECL:
3313 29992 : case FUNCTION_DECL:
3314 29992 : x = DECL_RTL (target);
3315 : break;
3316 :
3317 0 : case LABEL_DECL:
3318 0 : x = gen_rtx_MEM (FUNCTION_MODE,
3319 0 : gen_rtx_LABEL_REF (Pmode, force_label_rtx (target)));
3320 0 : break;
3321 :
3322 0 : case REAL_CST:
3323 0 : case FIXED_CST:
3324 0 : case STRING_CST:
3325 0 : case COMPLEX_CST:
3326 0 : case CONSTRUCTOR:
3327 0 : case INTEGER_CST:
3328 0 : x = lookup_constant_def (target);
3329 : /* Should have been added by output_addressed_constants. */
3330 0 : gcc_assert (x);
3331 : break;
3332 :
3333 0 : case INDIRECT_REF:
3334 : /* This deals with absolute addresses. */
3335 0 : offset += tree_to_shwi (TREE_OPERAND (target, 0));
3336 0 : x = gen_rtx_MEM (QImode,
3337 0 : gen_rtx_SYMBOL_REF (Pmode, "origin of addresses"));
3338 0 : break;
3339 :
3340 102 : case COMPOUND_LITERAL_EXPR:
3341 102 : gcc_assert (COMPOUND_LITERAL_EXPR_DECL (target));
3342 102 : x = DECL_RTL (COMPOUND_LITERAL_EXPR_DECL (target));
3343 : break;
3344 :
3345 0 : default:
3346 0 : gcc_unreachable ();
3347 : }
3348 :
3349 30094 : gcc_assert (MEM_P (x));
3350 30094 : x = XEXP (x, 0);
3351 :
3352 30094 : value->base = x;
3353 30094 : value->offset = offset;
3354 30094 : }
3355 :
3356 : static GTY(()) hash_table<tree_descriptor_hasher> *const_desc_htab;
3357 :
3358 : static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int);
3359 :
3360 : /* Constant pool accessor function. */
3361 :
3362 : hash_table<tree_descriptor_hasher> *
3363 2590 : constant_pool_htab (void)
3364 : {
3365 2590 : return const_desc_htab;
3366 : }
3367 :
3368 : /* Compute a hash code for a constant expression. */
3369 :
3370 : hashval_t
3371 9284466 : tree_descriptor_hasher::hash (constant_descriptor_tree *ptr)
3372 : {
3373 9284466 : return ptr->hash;
3374 : }
3375 :
3376 : static hashval_t
3377 5557678 : const_hash_1 (const tree exp)
3378 : {
3379 5832091 : const char *p;
3380 5832091 : hashval_t hi;
3381 5832091 : int len, i;
3382 5832091 : enum tree_code code = TREE_CODE (exp);
3383 :
3384 : /* Either set P and LEN to the address and len of something to hash and
3385 : exit the switch or return a value. */
3386 :
3387 5832091 : switch (code)
3388 : {
3389 698796 : case INTEGER_CST:
3390 698796 : p = (char *) &TREE_INT_CST_ELT (exp, 0);
3391 698796 : len = TREE_INT_CST_NUNITS (exp) * sizeof (HOST_WIDE_INT);
3392 698796 : break;
3393 :
3394 42008 : case REAL_CST:
3395 42008 : return real_hash (TREE_REAL_CST_PTR (exp));
3396 :
3397 0 : case FIXED_CST:
3398 0 : return fixed_hash (TREE_FIXED_CST_PTR (exp));
3399 :
3400 4560972 : case STRING_CST:
3401 4560972 : p = TREE_STRING_POINTER (exp);
3402 4560972 : len = TREE_STRING_LENGTH (exp);
3403 4560972 : break;
3404 :
3405 19499 : case COMPLEX_CST:
3406 19499 : return (const_hash_1 (TREE_REALPART (exp)) * 5
3407 19499 : + const_hash_1 (TREE_IMAGPART (exp)));
3408 :
3409 0 : case VECTOR_CST:
3410 0 : {
3411 0 : hi = 7 + VECTOR_CST_NPATTERNS (exp);
3412 0 : hi = hi * 563 + VECTOR_CST_NELTS_PER_PATTERN (exp);
3413 0 : unsigned int count = vector_cst_encoded_nelts (exp);
3414 0 : for (unsigned int i = 0; i < count; ++i)
3415 0 : hi = hi * 563 + const_hash_1 (VECTOR_CST_ENCODED_ELT (exp, i));
3416 : return hi;
3417 : }
3418 :
3419 163 : case RAW_DATA_CST:
3420 163 : p = RAW_DATA_POINTER (exp);
3421 163 : len = RAW_DATA_LENGTH (exp);
3422 163 : break;
3423 :
3424 225650 : case CONSTRUCTOR:
3425 225650 : {
3426 225650 : unsigned HOST_WIDE_INT idx;
3427 225650 : tree value;
3428 :
3429 225650 : hi = 5 + int_size_in_bytes (TREE_TYPE (exp));
3430 :
3431 1204085 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
3432 978435 : if (value)
3433 978435 : hi = hi * 603 + const_hash_1 (value);
3434 :
3435 : return hi;
3436 : }
3437 :
3438 125146 : case ADDR_EXPR:
3439 125146 : if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0)))
3440 95058 : return const_hash_1 (TREE_OPERAND (exp, 0));
3441 :
3442 : /* Fallthru. */
3443 30088 : case FDESC_EXPR:
3444 30088 : {
3445 30088 : class addr_const value;
3446 :
3447 30088 : decode_addr_const (exp, &value);
3448 30088 : switch (GET_CODE (value.base))
3449 : {
3450 30088 : case SYMBOL_REF:
3451 : /* Don't hash the address of the SYMBOL_REF;
3452 : only use the offset and the symbol name. */
3453 30088 : hi = value.offset.coeffs[0];
3454 30088 : p = XSTR (value.base, 0);
3455 1127764 : for (i = 0; p[i] != 0; i++)
3456 1097676 : hi = ((hi * 613) + (unsigned) (p[i]));
3457 : break;
3458 :
3459 0 : case LABEL_REF:
3460 0 : hi = (value.offset.coeffs[0]
3461 0 : + CODE_LABEL_NUMBER (label_ref_label (value.base)) * 13);
3462 0 : break;
3463 :
3464 0 : default:
3465 0 : gcc_unreachable ();
3466 : }
3467 : }
3468 30088 : return hi;
3469 :
3470 24 : case PLUS_EXPR:
3471 24 : case POINTER_PLUS_EXPR:
3472 24 : case MINUS_EXPR:
3473 24 : return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9
3474 24 : + const_hash_1 (TREE_OPERAND (exp, 1)));
3475 :
3476 159832 : CASE_CONVERT:
3477 159832 : return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2;
3478 :
3479 : default:
3480 : /* A language specific constant. Just hash the code. */
3481 : return code;
3482 : }
3483 :
3484 : /* Compute hashing function. */
3485 5259931 : hi = len;
3486 335529495 : for (i = 0; i < len; i++)
3487 330269564 : hi = ((hi * 613) + (unsigned) (p[i]));
3488 :
3489 : return hi;
3490 : }
3491 :
3492 : /* Wrapper of compare_constant, for the htab interface. */
3493 : bool
3494 13036236 : tree_descriptor_hasher::equal (constant_descriptor_tree *c1,
3495 : constant_descriptor_tree *c2)
3496 : {
3497 13036236 : if (c1->hash != c2->hash)
3498 : return false;
3499 3072156 : return compare_constant (c1->value, c2->value);
3500 : }
3501 :
3502 : /* Compare t1 and t2, and return true only if they are known to result in
3503 : the same bit pattern on output. */
3504 :
3505 : static bool
3506 3534706 : compare_constant (const tree t1, const tree t2)
3507 : {
3508 3537906 : enum tree_code typecode;
3509 :
3510 3537906 : if (t1 == NULL_TREE)
3511 28674 : return t2 == NULL_TREE;
3512 3509232 : if (t2 == NULL_TREE)
3513 : return false;
3514 :
3515 3509232 : if (TREE_CODE (t1) != TREE_CODE (t2))
3516 : return false;
3517 :
3518 3509204 : switch (TREE_CODE (t1))
3519 : {
3520 422964 : case INTEGER_CST:
3521 : /* Integer constants are the same only if the same width of type. */
3522 422964 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3523 : return false;
3524 413227 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3525 : return false;
3526 413155 : return tree_int_cst_equal (t1, t2);
3527 :
3528 38707 : case REAL_CST:
3529 : /* Real constants are the same only if the same width of type. In
3530 : addition to the same width, we need to check whether the modes are the
3531 : same. There might be two floating point modes that are the same size
3532 : but have different representations, such as the PowerPC that has 2
3533 : different 128-bit floating point types (IBM extended double and IEEE
3534 : 128-bit floating point). */
3535 38707 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3536 : return false;
3537 26037 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)))
3538 : return false;
3539 26037 : return real_identical (&TREE_REAL_CST (t1), &TREE_REAL_CST (t2));
3540 :
3541 0 : case FIXED_CST:
3542 : /* Fixed constants are the same only if the same width of type. */
3543 0 : if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2)))
3544 : return false;
3545 :
3546 0 : return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2));
3547 :
3548 2989982 : case STRING_CST:
3549 2989982 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3550 5979964 : || int_size_in_bytes (TREE_TYPE (t1))
3551 2989982 : != int_size_in_bytes (TREE_TYPE (t2)))
3552 : return false;
3553 :
3554 2989930 : return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2)
3555 2989930 : && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2),
3556 2989930 : TREE_STRING_LENGTH (t1)));
3557 :
3558 25471 : case COMPLEX_CST:
3559 25471 : return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2))
3560 40155 : && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2)));
3561 :
3562 0 : case VECTOR_CST:
3563 0 : {
3564 0 : if (VECTOR_CST_NPATTERNS (t1)
3565 0 : != VECTOR_CST_NPATTERNS (t2))
3566 : return false;
3567 :
3568 0 : if (VECTOR_CST_NELTS_PER_PATTERN (t1)
3569 0 : != VECTOR_CST_NELTS_PER_PATTERN (t2))
3570 : return false;
3571 :
3572 0 : unsigned int count = vector_cst_encoded_nelts (t1);
3573 0 : for (unsigned int i = 0; i < count; ++i)
3574 0 : if (!compare_constant (VECTOR_CST_ENCODED_ELT (t1, i),
3575 0 : VECTOR_CST_ENCODED_ELT (t2, i)))
3576 : return false;
3577 :
3578 : return true;
3579 : }
3580 :
3581 75 : case RAW_DATA_CST:
3582 75 : return (RAW_DATA_LENGTH (t1) == RAW_DATA_LENGTH (t2)
3583 75 : && ! memcmp (RAW_DATA_POINTER (t1), RAW_DATA_POINTER (t2),
3584 75 : RAW_DATA_LENGTH (t1)));
3585 :
3586 28802 : case CONSTRUCTOR:
3587 28802 : {
3588 28802 : vec<constructor_elt, va_gc> *v1, *v2;
3589 28802 : unsigned HOST_WIDE_INT idx;
3590 :
3591 28802 : typecode = TREE_CODE (TREE_TYPE (t1));
3592 28802 : if (typecode != TREE_CODE (TREE_TYPE (t2)))
3593 : return false;
3594 :
3595 28802 : if (typecode == ARRAY_TYPE)
3596 : {
3597 835 : HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1));
3598 : /* For arrays, check that mode, size and storage order match. */
3599 835 : if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))
3600 835 : || size_1 == -1
3601 835 : || size_1 != int_size_in_bytes (TREE_TYPE (t2))
3602 1670 : || TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t1))
3603 835 : != TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (t2)))
3604 : return false;
3605 : }
3606 : else
3607 : {
3608 : /* For record and union constructors, require exact type
3609 : equality. */
3610 27967 : if (TREE_TYPE (t1) != TREE_TYPE (t2))
3611 : return false;
3612 : }
3613 :
3614 28794 : v1 = CONSTRUCTOR_ELTS (t1);
3615 28794 : v2 = CONSTRUCTOR_ELTS (t2);
3616 86382 : if (vec_safe_length (v1) != vec_safe_length (v2))
3617 : return false;
3618 :
3619 282592 : for (idx = 0; idx < vec_safe_length (v1); ++idx)
3620 : {
3621 253807 : constructor_elt *c1 = &(*v1)[idx];
3622 253807 : constructor_elt *c2 = &(*v2)[idx];
3623 :
3624 : /* Check that each value is the same... */
3625 253807 : if (!compare_constant (c1->value, c2->value))
3626 : return false;
3627 : /* ... and that they apply to the same fields! */
3628 253798 : if (typecode == ARRAY_TYPE)
3629 : {
3630 168588 : if (!compare_constant (c1->index, c2->index))
3631 : return false;
3632 : }
3633 : else
3634 : {
3635 85210 : if (c1->index != c2->index)
3636 : return false;
3637 : }
3638 : }
3639 :
3640 : return true;
3641 : }
3642 :
3643 3 : case ADDR_EXPR:
3644 3 : case FDESC_EXPR:
3645 3 : {
3646 3 : class addr_const value1, value2;
3647 3 : enum rtx_code code;
3648 3 : bool ret;
3649 :
3650 3 : decode_addr_const (t1, &value1);
3651 3 : decode_addr_const (t2, &value2);
3652 :
3653 3 : if (maybe_ne (value1.offset, value2.offset))
3654 : return false;
3655 :
3656 3 : code = GET_CODE (value1.base);
3657 3 : if (code != GET_CODE (value2.base))
3658 : return false;
3659 :
3660 3 : switch (code)
3661 : {
3662 3 : case SYMBOL_REF:
3663 3 : ret = (strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0);
3664 3 : break;
3665 :
3666 0 : case LABEL_REF:
3667 0 : ret = (CODE_LABEL_NUMBER (label_ref_label (value1.base))
3668 0 : == CODE_LABEL_NUMBER (label_ref_label (value2.base)));
3669 0 : break;
3670 :
3671 0 : default:
3672 0 : gcc_unreachable ();
3673 : }
3674 : return ret;
3675 : }
3676 :
3677 0 : case PLUS_EXPR:
3678 0 : case POINTER_PLUS_EXPR:
3679 0 : case MINUS_EXPR:
3680 0 : case RANGE_EXPR:
3681 0 : return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))
3682 0 : && compare_constant (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)));
3683 :
3684 3200 : CASE_CONVERT:
3685 3200 : case VIEW_CONVERT_EXPR:
3686 3200 : return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0));
3687 :
3688 : default:
3689 : return false;
3690 : }
3691 : }
3692 :
3693 : /* Return the section into which constant EXP should be placed. */
3694 :
3695 : static section *
3696 1290843 : get_constant_section (tree exp, unsigned int align)
3697 : {
3698 1290843 : return targetm.asm_out.select_section (exp,
3699 : compute_reloc_for_constant (exp),
3700 1290843 : align);
3701 : }
3702 :
3703 : /* Return the size of constant EXP in bytes. */
3704 :
3705 : static HOST_WIDE_INT
3706 1292734 : get_constant_size (tree exp)
3707 : {
3708 1292734 : HOST_WIDE_INT size;
3709 :
3710 1292734 : size = int_size_in_bytes (TREE_TYPE (exp));
3711 1292734 : gcc_checking_assert (size >= 0);
3712 1292734 : gcc_checking_assert (TREE_CODE (exp) != STRING_CST
3713 : || size >= TREE_STRING_LENGTH (exp));
3714 1292734 : return size;
3715 : }
3716 :
3717 : /* Subroutine of output_constant_def:
3718 : No constant equal to EXP is known to have been output.
3719 : Make a constant descriptor to enter EXP in the hash table.
3720 : Assign the label number and construct RTL to refer to the
3721 : constant's location in memory.
3722 : Caller is responsible for updating the hash table. */
3723 :
3724 : static struct constant_descriptor_tree *
3725 1299083 : build_constant_desc (tree exp)
3726 : {
3727 1299083 : struct constant_descriptor_tree *desc;
3728 1299083 : rtx symbol, rtl;
3729 1299083 : char label[256];
3730 1299083 : int labelno;
3731 1299083 : tree decl;
3732 :
3733 1299083 : desc = ggc_alloc<constant_descriptor_tree> ();
3734 1299083 : desc->value = exp;
3735 :
3736 : /* Create a string containing the label name, in LABEL. */
3737 1299083 : labelno = const_labelno++;
3738 1299083 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno);
3739 :
3740 : /* Construct the VAR_DECL associated with the constant. */
3741 1299083 : decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, get_identifier (label),
3742 1299083 : TREE_TYPE (exp));
3743 1299083 : DECL_ARTIFICIAL (decl) = 1;
3744 1299083 : DECL_IGNORED_P (decl) = 1;
3745 1299083 : TREE_READONLY (decl) = 1;
3746 1299083 : TREE_STATIC (decl) = 1;
3747 1299083 : TREE_ADDRESSABLE (decl) = 1;
3748 : /* We don't set the RTL yet as this would cause varpool to assume that the
3749 : variable is referenced. Moreover, it would just be dropped in LTO mode.
3750 : Instead we set the flag that will be recognized in make_decl_rtl. */
3751 1299083 : DECL_IN_CONSTANT_POOL (decl) = 1;
3752 1299083 : DECL_INITIAL (decl) = desc->value;
3753 : /* ??? targetm.constant_alignment hasn't been updated for vector types on
3754 : most architectures so use DATA_ALIGNMENT as well, except for strings. */
3755 1299083 : if (TREE_CODE (exp) == STRING_CST)
3756 1266909 : SET_DECL_ALIGN (decl, targetm.constant_alignment (exp, DECL_ALIGN (decl)));
3757 : else
3758 : {
3759 32174 : align_variable (decl, 0);
3760 32174 : if (DECL_ALIGN (decl) < GET_MODE_ALIGNMENT (DECL_MODE (decl))
3761 32174 : && ((optab_handler (movmisalign_optab, DECL_MODE (decl))
3762 : != CODE_FOR_nothing)
3763 0 : || targetm.slow_unaligned_access (DECL_MODE (decl),
3764 0 : DECL_ALIGN (decl))))
3765 0 : SET_DECL_ALIGN (decl, GET_MODE_ALIGNMENT (DECL_MODE (decl)));
3766 : }
3767 :
3768 : /* Now construct the SYMBOL_REF and the MEM. */
3769 1299083 : if (use_object_blocks_p ())
3770 : {
3771 0 : int align = (TREE_CODE (decl) == CONST_DECL
3772 0 : || (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
3773 0 : ? DECL_ALIGN (decl)
3774 0 : : symtab_node::get (decl)->definition_alignment ());
3775 0 : section *sect = get_constant_section (exp, align);
3776 0 : symbol = create_block_symbol (ggc_strdup (label),
3777 : get_block_for_section (sect), -1);
3778 : }
3779 : else
3780 1595894 : symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
3781 1299083 : SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
3782 1299083 : SET_SYMBOL_REF_DECL (symbol, decl);
3783 1299083 : TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1;
3784 :
3785 1299083 : rtl = gen_const_mem (TYPE_MODE (TREE_TYPE (exp)), symbol);
3786 1299083 : set_mem_alias_set (rtl, 0);
3787 :
3788 : /* Putting EXP into the literal pool might have imposed a different
3789 : alignment which should be visible in the RTX as well. */
3790 1299083 : set_mem_align (rtl, DECL_ALIGN (decl));
3791 :
3792 : /* We cannot share RTX'es in pool entries.
3793 : Mark this piece of RTL as required for unsharing. */
3794 1299083 : RTX_FLAG (rtl, used) = 1;
3795 :
3796 : /* Set flags or add text to the name to record information, such as
3797 : that it is a local symbol. If the name is changed, the macro
3798 : ASM_OUTPUT_LABELREF will have to know how to strip this
3799 : information. This call might invalidate our local variable
3800 : SYMBOL; we can't use it afterward. */
3801 1299083 : targetm.encode_section_info (exp, rtl, true);
3802 :
3803 1299083 : desc->rtl = rtl;
3804 :
3805 1299083 : return desc;
3806 : }
3807 :
3808 : /* Subroutine of output_constant_def and tree_output_constant_def:
3809 : Add a constant to the hash table that tracks which constants
3810 : already have labels. */
3811 :
3812 : static constant_descriptor_tree *
3813 4073437 : add_constant_to_table (tree exp, int defer)
3814 : {
3815 : /* The hash table methods may call output_constant_def for addressed
3816 : constants, so handle them first. */
3817 4073437 : output_addressed_constants (exp, defer);
3818 :
3819 : /* Sanity check to catch recursive insertion. */
3820 4073437 : static bool inserting;
3821 4073437 : gcc_assert (!inserting);
3822 4073437 : inserting = true;
3823 :
3824 : /* Look up EXP in the table of constant descriptors. If we didn't
3825 : find it, create a new one. */
3826 4073437 : struct constant_descriptor_tree key;
3827 4073437 : key.value = exp;
3828 4073437 : key.hash = const_hash_1 (exp);
3829 4073437 : constant_descriptor_tree **loc
3830 4073437 : = const_desc_htab->find_slot_with_hash (&key, key.hash, INSERT);
3831 :
3832 4073437 : inserting = false;
3833 :
3834 4073437 : struct constant_descriptor_tree *desc = *loc;
3835 4073437 : if (!desc)
3836 : {
3837 1299083 : desc = build_constant_desc (exp);
3838 1299083 : desc->hash = key.hash;
3839 1299083 : *loc = desc;
3840 : }
3841 :
3842 4073437 : return desc;
3843 : }
3844 :
3845 : /* Return an rtx representing a reference to constant data in memory
3846 : for the constant expression EXP.
3847 :
3848 : If assembler code for such a constant has already been output,
3849 : return an rtx to refer to it.
3850 : Otherwise, output such a constant in memory
3851 : and generate an rtx for it.
3852 :
3853 : If DEFER is nonzero, this constant can be deferred and output only
3854 : if referenced in the function after all optimizations.
3855 :
3856 : `const_desc_table' records which constants already have label strings. */
3857 :
3858 : rtx
3859 4062187 : output_constant_def (tree exp, int defer)
3860 : {
3861 4062187 : struct constant_descriptor_tree *desc = add_constant_to_table (exp, defer);
3862 4062187 : maybe_output_constant_def_contents (desc, defer);
3863 4062187 : return desc->rtl;
3864 : }
3865 :
3866 : /* Subroutine of output_constant_def: Decide whether or not we need to
3867 : output the constant DESC now, and if so, do it. */
3868 : static void
3869 4062187 : maybe_output_constant_def_contents (struct constant_descriptor_tree *desc,
3870 : int defer)
3871 : {
3872 4062187 : rtx symbol = XEXP (desc->rtl, 0);
3873 4062187 : tree exp = desc->value;
3874 :
3875 4062187 : if (flag_syntax_only)
3876 : return;
3877 :
3878 4062187 : if (TREE_ASM_WRITTEN (exp))
3879 : /* Already output; don't do it again. */
3880 : return;
3881 :
3882 : /* We can always defer constants as long as the context allows
3883 : doing so. */
3884 1461758 : if (defer)
3885 : {
3886 : /* Increment n_deferred_constants if it exists. It needs to be at
3887 : least as large as the number of constants actually referred to
3888 : by the function. If it's too small we'll stop looking too early
3889 : and fail to emit constants; if it's too large we'll only look
3890 : through the entire function when we could have stopped earlier. */
3891 180362 : if (cfun)
3892 108977 : n_deferred_constants++;
3893 : return;
3894 : }
3895 :
3896 1281396 : output_constant_def_contents (symbol);
3897 : }
3898 :
3899 : /* Subroutine of output_constant_def_contents. Output the definition
3900 : of constant EXP, which is pointed to by label LABEL. ALIGN is the
3901 : constant's alignment in bits. */
3902 :
3903 : static void
3904 1290843 : assemble_constant_contents (tree exp, const char *label, unsigned int align,
3905 : bool merge_strings)
3906 : {
3907 1290843 : HOST_WIDE_INT size;
3908 :
3909 1290843 : size = get_constant_size (exp);
3910 :
3911 : /* Do any machine/system dependent processing of the constant. */
3912 1290843 : targetm.asm_out.declare_constant_name (asm_out_file, label, exp, size);
3913 :
3914 : /* Output the value of EXP. */
3915 1290843 : output_constant (exp, size, align, false, merge_strings);
3916 :
3917 1290843 : targetm.asm_out.decl_end ();
3918 1290843 : }
3919 :
3920 : /* We must output the constant data referred to by SYMBOL; do so. */
3921 :
3922 : static void
3923 1290843 : output_constant_def_contents (rtx symbol)
3924 : {
3925 1290843 : tree decl = SYMBOL_REF_DECL (symbol);
3926 1290843 : tree exp = DECL_INITIAL (decl);
3927 1290843 : bool asan_protected = false;
3928 :
3929 : /* Make sure any other constants whose addresses appear in EXP
3930 : are assigned label numbers. */
3931 1290843 : output_addressed_constants (exp, 0);
3932 :
3933 : /* We are no longer deferring this constant. */
3934 1290843 : TREE_ASM_WRITTEN (decl) = TREE_ASM_WRITTEN (exp) = 1;
3935 :
3936 1290843 : if ((flag_sanitize & SANITIZE_ADDRESS)
3937 3670 : && TREE_CODE (exp) == STRING_CST
3938 1294477 : && asan_protect_global (exp))
3939 : {
3940 1891 : asan_protected = true;
3941 1891 : SET_DECL_ALIGN (decl, MAX (DECL_ALIGN (decl),
3942 : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT));
3943 : }
3944 :
3945 : /* If the constant is part of an object block, make sure that the
3946 : decl has been positioned within its block, but do not write out
3947 : its definition yet. output_object_blocks will do that later. */
3948 1290843 : if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol))
3949 0 : place_block_symbol (symbol);
3950 : else
3951 : {
3952 1290843 : int align = (TREE_CODE (decl) == CONST_DECL
3953 1290843 : || (VAR_P (decl) && DECL_IN_CONSTANT_POOL (decl))
3954 2581686 : ? DECL_ALIGN (decl)
3955 1290843 : : symtab_node::get (decl)->definition_alignment ());
3956 1290843 : section *sect = get_constant_section (exp, align);
3957 1290843 : switch_to_section (sect);
3958 1290843 : if (align > BITS_PER_UNIT)
3959 404048 : ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3960 1290843 : assemble_constant_contents (exp, XSTR (symbol, 0), align,
3961 1290843 : (sect->common.flags & SECTION_MERGE)
3962 413189 : && (sect->common.flags & SECTION_STRINGS));
3963 1290843 : if (asan_protected)
3964 : {
3965 1891 : HOST_WIDE_INT size = get_constant_size (exp);
3966 3741 : assemble_zeros (asan_red_zone_size (size));
3967 : }
3968 : }
3969 1290843 : }
3970 :
3971 : /* Look up EXP in the table of constant descriptors. Return the rtl
3972 : if it has been emitted, else null. */
3973 :
3974 : rtx
3975 486283 : lookup_constant_def (tree exp)
3976 : {
3977 486283 : struct constant_descriptor_tree key;
3978 :
3979 486283 : key.value = exp;
3980 486283 : key.hash = const_hash_1 (exp);
3981 486283 : constant_descriptor_tree *desc
3982 486283 : = const_desc_htab->find_with_hash (&key, key.hash);
3983 :
3984 486283 : return (desc ? desc->rtl : NULL_RTX);
3985 : }
3986 :
3987 : /* Return a tree representing a reference to constant data in memory
3988 : for the constant expression EXP.
3989 :
3990 : This is the counterpart of output_constant_def at the Tree level. */
3991 :
3992 : tree
3993 11250 : tree_output_constant_def (tree exp)
3994 : {
3995 11250 : struct constant_descriptor_tree *desc = add_constant_to_table (exp, 1);
3996 11250 : tree decl = SYMBOL_REF_DECL (XEXP (desc->rtl, 0));
3997 11250 : varpool_node::finalize_decl (decl);
3998 11250 : return decl;
3999 : }
4000 :
4001 4364880 : class GTY((chain_next ("%h.next"), for_user)) constant_descriptor_rtx {
4002 : public:
4003 : class constant_descriptor_rtx *next;
4004 : rtx mem;
4005 : rtx sym;
4006 : rtx constant;
4007 : HOST_WIDE_INT offset;
4008 : hashval_t hash;
4009 : fixed_size_mode mode;
4010 : unsigned int align;
4011 : int labelno;
4012 : int mark;
4013 : };
4014 :
4015 : struct const_rtx_desc_hasher : ggc_ptr_hash<constant_descriptor_rtx>
4016 : {
4017 : static hashval_t hash (constant_descriptor_rtx *);
4018 : static bool equal (constant_descriptor_rtx *, constant_descriptor_rtx *);
4019 : };
4020 :
4021 : /* Used in the hash tables to avoid outputting the same constant
4022 : twice. Unlike 'struct constant_descriptor_tree', RTX constants
4023 : are output once per function, not once per file. */
4024 : /* ??? Only a few targets need per-function constant pools. Most
4025 : can use one per-file pool. Should add a targetm bit to tell the
4026 : difference. */
4027 :
4028 : struct GTY(()) rtx_constant_pool {
4029 : /* Pointers to first and last constant in pool, as ordered by offset. */
4030 : class constant_descriptor_rtx *first;
4031 : class constant_descriptor_rtx *last;
4032 :
4033 : /* Hash facility for making memory-constants from constant rtl-expressions.
4034 : It is used on RISC machines where immediate integer arguments and
4035 : constant addresses are restricted so that such constants must be stored
4036 : in memory. */
4037 : hash_table<const_rtx_desc_hasher> *const_rtx_htab;
4038 :
4039 : /* Current offset in constant pool (does not include any
4040 : machine-specific header). */
4041 : HOST_WIDE_INT offset;
4042 : };
4043 :
4044 : /* Hash and compare functions for const_rtx_htab. */
4045 :
4046 : hashval_t
4047 17275900 : const_rtx_desc_hasher::hash (constant_descriptor_rtx *desc)
4048 : {
4049 17275900 : return desc->hash;
4050 : }
4051 :
4052 : bool
4053 21570990 : const_rtx_desc_hasher::equal (constant_descriptor_rtx *x,
4054 : constant_descriptor_rtx *y)
4055 : {
4056 21570990 : if (x->mode != y->mode)
4057 : return false;
4058 11516347 : return rtx_equal_p (x->constant, y->constant);
4059 : }
4060 :
4061 : /* Hash one component of a constant. */
4062 :
4063 : static hashval_t
4064 16885825 : const_rtx_hash_1 (const_rtx x)
4065 : {
4066 16885825 : unsigned HOST_WIDE_INT hwi;
4067 16885825 : machine_mode mode;
4068 16885825 : enum rtx_code code;
4069 16885825 : hashval_t h;
4070 16885825 : int i;
4071 :
4072 16885825 : code = GET_CODE (x);
4073 16885825 : mode = GET_MODE (x);
4074 16885825 : h = (hashval_t) code * 1048573 + mode;
4075 :
4076 16885825 : switch (code)
4077 : {
4078 11313451 : case CONST_INT:
4079 11313451 : hwi = INTVAL (x);
4080 :
4081 11435017 : fold_hwi:
4082 11435017 : {
4083 11435017 : int shift = sizeof (hashval_t) * CHAR_BIT;
4084 11435017 : const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t);
4085 :
4086 11435017 : h ^= (hashval_t) hwi;
4087 22870034 : for (i = 1; i < n; ++i)
4088 : {
4089 11435017 : hwi >>= shift;
4090 11435017 : h ^= (hashval_t) hwi;
4091 : }
4092 : }
4093 : break;
4094 :
4095 : case CONST_WIDE_INT:
4096 : hwi = 0;
4097 : {
4098 375402 : for (i = 0; i < CONST_WIDE_INT_NUNITS (x); i++)
4099 253836 : hwi ^= CONST_WIDE_INT_ELT (x, i);
4100 121566 : goto fold_hwi;
4101 : }
4102 :
4103 2943543 : case CONST_DOUBLE:
4104 2943543 : if (TARGET_SUPPORTS_WIDE_INT == 0 && mode == VOIDmode)
4105 : {
4106 : hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x);
4107 : goto fold_hwi;
4108 : }
4109 : else
4110 2943543 : h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x));
4111 2943543 : break;
4112 :
4113 0 : case CONST_FIXED:
4114 0 : h ^= fixed_hash (CONST_FIXED_VALUE (x));
4115 0 : break;
4116 :
4117 90182 : case SYMBOL_REF:
4118 90182 : h ^= htab_hash_string (XSTR (x, 0));
4119 90182 : break;
4120 :
4121 38 : case LABEL_REF:
4122 38 : h = h * 251 + CODE_LABEL_NUMBER (label_ref_label (x));
4123 38 : break;
4124 :
4125 0 : case UNSPEC:
4126 0 : case UNSPEC_VOLATILE:
4127 0 : h = h * 251 + XINT (x, 1);
4128 0 : break;
4129 :
4130 : default:
4131 : break;
4132 : }
4133 :
4134 16885825 : return h;
4135 : }
4136 :
4137 : /* Compute a hash value for X, which should be a constant. */
4138 :
4139 : static hashval_t
4140 4343692 : const_rtx_hash (rtx x)
4141 : {
4142 4343692 : hashval_t h = 0;
4143 4343692 : subrtx_iterator::array_type array;
4144 21229517 : FOR_EACH_SUBRTX (iter, array, x, ALL)
4145 16885825 : h = h * 509 + const_rtx_hash_1 (*iter);
4146 4343692 : return h;
4147 4343692 : }
4148 :
4149 :
4150 : /* Create and return a new rtx constant pool. */
4151 :
4152 : static struct rtx_constant_pool *
4153 2059427 : create_constant_pool (void)
4154 : {
4155 2059427 : struct rtx_constant_pool *pool;
4156 :
4157 2059427 : pool = ggc_alloc<rtx_constant_pool> ();
4158 2059427 : pool->const_rtx_htab = hash_table<const_rtx_desc_hasher>::create_ggc (31);
4159 2059427 : pool->first = NULL;
4160 2059427 : pool->last = NULL;
4161 2059427 : pool->offset = 0;
4162 2059427 : return pool;
4163 : }
4164 :
4165 : /* Initialize constant pool hashing for a new function. */
4166 :
4167 : void
4168 1764002 : init_varasm_status (void)
4169 : {
4170 1764002 : crtl->varasm.pool = create_constant_pool ();
4171 1764002 : crtl->varasm.deferred_constants = 0;
4172 1764002 : }
4173 :
4174 : /* Given a MINUS expression, simplify it if both sides
4175 : include the same symbol. */
4176 :
4177 : rtx
4178 5161069 : simplify_subtraction (rtx x)
4179 : {
4180 5161069 : rtx r = simplify_rtx (x);
4181 5161069 : return r ? r : x;
4182 : }
4183 :
4184 : /* Given a constant rtx X, make (or find) a memory constant for its value
4185 : and return a MEM rtx to refer to it in memory. IN_MODE is the mode
4186 : of X. */
4187 :
4188 : rtx
4189 4364880 : force_const_mem (machine_mode in_mode, rtx x)
4190 : {
4191 4364880 : class constant_descriptor_rtx *desc, tmp;
4192 4364880 : struct rtx_constant_pool *pool;
4193 4364880 : char label[256];
4194 4364880 : rtx def, symbol;
4195 4364880 : hashval_t hash;
4196 4364880 : unsigned int align;
4197 4364880 : constant_descriptor_rtx **slot;
4198 4364880 : fixed_size_mode mode;
4199 :
4200 : /* We can't force variable-sized objects to memory. */
4201 4364880 : if (!is_a <fixed_size_mode> (in_mode, &mode))
4202 : return NULL_RTX;
4203 :
4204 : /* If we're not allowed to drop X into the constant pool, don't. */
4205 4364880 : if (targetm.cannot_force_const_mem (mode, x))
4206 : return NULL_RTX;
4207 :
4208 : /* Record that this function has used a constant pool entry. */
4209 4343692 : crtl->uses_const_pool = 1;
4210 :
4211 : /* Decide which pool to use. */
4212 8687384 : pool = (targetm.use_blocks_for_constant_p (mode, x)
4213 4343692 : ? shared_constant_pool
4214 : : crtl->varasm.pool);
4215 :
4216 : /* Lookup the value in the hashtable. */
4217 4343692 : tmp.constant = x;
4218 4343692 : tmp.mode = mode;
4219 4343692 : hash = const_rtx_hash (x);
4220 4343692 : slot = pool->const_rtx_htab->find_slot_with_hash (&tmp, hash, INSERT);
4221 4343692 : desc = *slot;
4222 :
4223 : /* If the constant was already present, return its memory. */
4224 4343692 : if (desc)
4225 3980621 : return copy_rtx (desc->mem);
4226 :
4227 : /* Otherwise, create a new descriptor. */
4228 363071 : desc = ggc_alloc<constant_descriptor_rtx> ();
4229 363071 : *slot = desc;
4230 :
4231 : /* Align the location counter as required by EXP's data type. */
4232 363071 : machine_mode align_mode = (mode == VOIDmode ? word_mode : mode);
4233 363071 : align = targetm.static_rtx_alignment (align_mode);
4234 :
4235 363071 : pool->offset += (align / BITS_PER_UNIT) - 1;
4236 363071 : pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
4237 :
4238 363071 : desc->next = NULL;
4239 363071 : desc->constant = copy_rtx (tmp.constant);
4240 363071 : desc->offset = pool->offset;
4241 363071 : desc->hash = hash;
4242 363071 : desc->mode = mode;
4243 363071 : desc->align = align;
4244 363071 : desc->labelno = const_labelno;
4245 363071 : desc->mark = 0;
4246 :
4247 363071 : pool->offset += GET_MODE_SIZE (mode);
4248 363071 : if (pool->last)
4249 316442 : pool->last->next = desc;
4250 : else
4251 46629 : pool->first = pool->last = desc;
4252 363071 : pool->last = desc;
4253 :
4254 : /* Create a string containing the label name, in LABEL. */
4255 363071 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
4256 363071 : ++const_labelno;
4257 :
4258 : /* Construct the SYMBOL_REF. Make sure to mark it as belonging to
4259 : the constants pool. */
4260 363071 : if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x))
4261 : {
4262 0 : section *sect = targetm.asm_out.select_rtx_section (mode, x, align);
4263 0 : symbol = create_block_symbol (ggc_strdup (label),
4264 : get_block_for_section (sect), -1);
4265 : }
4266 : else
4267 395286 : symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label));
4268 363071 : desc->sym = symbol;
4269 363071 : SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL;
4270 363071 : CONSTANT_POOL_ADDRESS_P (symbol) = 1;
4271 363071 : SET_SYMBOL_REF_CONSTANT (symbol, desc);
4272 :
4273 : /* Construct the MEM. */
4274 363071 : desc->mem = def = gen_const_mem (mode, symbol);
4275 363071 : set_mem_align (def, align);
4276 :
4277 : /* If we're dropping a label to the constant pool, make sure we
4278 : don't delete it. */
4279 363071 : if (GET_CODE (x) == LABEL_REF)
4280 38 : LABEL_PRESERVE_P (XEXP (x, 0)) = 1;
4281 :
4282 363071 : return copy_rtx (def);
4283 : }
4284 :
4285 : /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
4286 :
4287 : rtx
4288 12660372 : get_pool_constant (const_rtx addr)
4289 : {
4290 12660372 : return SYMBOL_REF_CONSTANT (addr)->constant;
4291 : }
4292 :
4293 : /* Given a constant pool SYMBOL_REF, return the corresponding constant
4294 : and whether it has been output or not. */
4295 :
4296 : rtx
4297 0 : get_pool_constant_mark (rtx addr, bool *pmarked)
4298 : {
4299 0 : class constant_descriptor_rtx *desc;
4300 :
4301 0 : desc = SYMBOL_REF_CONSTANT (addr);
4302 0 : *pmarked = (desc->mark != 0);
4303 0 : return desc->constant;
4304 : }
4305 :
4306 : /* Similar, return the mode. */
4307 :
4308 : fixed_size_mode
4309 5519554 : get_pool_mode (const_rtx addr)
4310 : {
4311 5519554 : return SYMBOL_REF_CONSTANT (addr)->mode;
4312 : }
4313 :
4314 : /* Return TRUE if and only if the constant pool has no entries. Note
4315 : that even entries we might end up choosing not to emit are counted
4316 : here, so there is the potential for missed optimizations. */
4317 :
4318 : bool
4319 0 : constant_pool_empty_p (void)
4320 : {
4321 0 : return crtl->varasm.pool->first == NULL;
4322 : }
4323 :
4324 : /* Worker function for output_constant_pool_1. Emit assembly for X
4325 : in MODE with known alignment ALIGN. */
4326 :
4327 : static void
4328 677929 : output_constant_pool_2 (fixed_size_mode mode, rtx x, unsigned int align)
4329 : {
4330 677929 : switch (GET_MODE_CLASS (mode))
4331 : {
4332 209697 : case MODE_FLOAT:
4333 209697 : case MODE_DECIMAL_FLOAT:
4334 209697 : {
4335 209697 : gcc_assert (CONST_DOUBLE_AS_FLOAT_P (x));
4336 209697 : assemble_real (*CONST_DOUBLE_REAL_VALUE (x),
4337 : as_a <scalar_float_mode> (mode), align, false);
4338 209697 : break;
4339 : }
4340 :
4341 373863 : case MODE_INT:
4342 373863 : case MODE_PARTIAL_INT:
4343 373863 : case MODE_FRACT:
4344 373863 : case MODE_UFRACT:
4345 373863 : case MODE_ACCUM:
4346 373863 : case MODE_UACCUM:
4347 373863 : assemble_integer (x, GET_MODE_SIZE (mode), align, 1);
4348 373863 : break;
4349 :
4350 0 : case MODE_VECTOR_BOOL:
4351 0 : {
4352 0 : gcc_assert (GET_CODE (x) == CONST_VECTOR);
4353 :
4354 0 : auto_vec<target_unit, 128> buffer;
4355 0 : buffer.reserve (GET_MODE_SIZE (mode));
4356 :
4357 0 : bool ok = native_encode_rtx (mode, x, buffer, 0, GET_MODE_SIZE (mode));
4358 0 : gcc_assert (ok);
4359 :
4360 0 : for (unsigned i = 0; i < GET_MODE_SIZE (mode); i++)
4361 : {
4362 0 : unsigned HOST_WIDE_INT value = buffer[i];
4363 0 : output_constant_pool_2 (byte_mode, gen_int_mode (value, byte_mode),
4364 : i == 0 ? align : 1);
4365 : }
4366 0 : break;
4367 0 : }
4368 94369 : case MODE_VECTOR_FLOAT:
4369 94369 : case MODE_VECTOR_INT:
4370 94369 : case MODE_VECTOR_FRACT:
4371 94369 : case MODE_VECTOR_UFRACT:
4372 94369 : case MODE_VECTOR_ACCUM:
4373 94369 : case MODE_VECTOR_UACCUM:
4374 94369 : {
4375 94369 : int i, units;
4376 94369 : scalar_mode submode = GET_MODE_INNER (mode);
4377 283107 : unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode));
4378 :
4379 94369 : gcc_assert (GET_CODE (x) == CONST_VECTOR);
4380 94369 : units = GET_MODE_NUNITS (mode);
4381 :
4382 520730 : for (i = 0; i < units; i++)
4383 : {
4384 426361 : rtx elt = CONST_VECTOR_ELT (x, i);
4385 520730 : output_constant_pool_2 (submode, elt, i ? subalign : align);
4386 : }
4387 : }
4388 : break;
4389 :
4390 0 : default:
4391 0 : gcc_unreachable ();
4392 : }
4393 677929 : }
4394 :
4395 : /* Worker function for output_constant_pool. Emit constant DESC,
4396 : giving it ALIGN bits of alignment. */
4397 :
4398 : static void
4399 251568 : output_constant_pool_1 (class constant_descriptor_rtx *desc,
4400 : unsigned int align)
4401 : {
4402 251568 : rtx x, tmp;
4403 :
4404 251568 : x = desc->constant;
4405 :
4406 : /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
4407 : whose CODE_LABEL has been deleted. This can occur if a jump table
4408 : is eliminated by optimization. If so, write a constant of zero
4409 : instead. Note that this can also happen by turning the
4410 : CODE_LABEL into a NOTE. */
4411 : /* ??? This seems completely and utterly wrong. Certainly it's
4412 : not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
4413 : functioning even with rtx_insn::deleted and friends. */
4414 :
4415 251568 : tmp = x;
4416 251568 : switch (GET_CODE (tmp))
4417 : {
4418 3625 : case CONST:
4419 3625 : if (GET_CODE (XEXP (tmp, 0)) != PLUS
4420 3625 : || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF)
4421 : break;
4422 : tmp = XEXP (XEXP (tmp, 0), 0);
4423 : /* FALLTHRU */
4424 :
4425 38 : case LABEL_REF:
4426 38 : {
4427 38 : rtx_insn *insn = label_ref_label (tmp);
4428 38 : gcc_assert (!insn->deleted ());
4429 38 : gcc_assert (!NOTE_P (insn)
4430 : || NOTE_KIND (insn) != NOTE_INSN_DELETED);
4431 : break;
4432 : }
4433 :
4434 : default:
4435 : break;
4436 : }
4437 :
4438 : #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4439 : ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode,
4440 : align, desc->labelno, done);
4441 : #endif
4442 :
4443 251568 : assemble_align (align);
4444 :
4445 : /* Output the label. */
4446 251568 : targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno);
4447 :
4448 : /* Output the data.
4449 : Pass actual alignment value while emitting string constant to asm code
4450 : as function 'output_constant_pool_1' explicitly passes the alignment as 1
4451 : assuming that the data is already aligned which prevents the generation
4452 : of fix-up table entries. */
4453 251568 : output_constant_pool_2 (desc->mode, x, desc->align);
4454 :
4455 : /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS
4456 : sections have proper size. */
4457 251568 : if (in_section
4458 251568 : && (in_section->common.flags & SECTION_MERGE)
4459 251568 : && ((in_section->common.flags & SECTION_ENTSIZE)
4460 415026 : > GET_MODE_SIZE (desc->mode)))
4461 : {
4462 99 : unsigned HOST_WIDE_INT entsize, constsize;
4463 99 : entsize = (in_section->common.flags & SECTION_ENTSIZE);
4464 99 : constsize = GET_MODE_SIZE (desc->mode);
4465 99 : assemble_zeros (entsize - constsize);
4466 : }
4467 :
4468 : #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
4469 : done:
4470 : #endif
4471 251568 : return;
4472 : }
4473 :
4474 : /* Recompute the offsets of entries in POOL, and the overall size of
4475 : POOL. Do this after calling mark_constant_pool to ensure that we
4476 : are computing the offset values for the pool which we will actually
4477 : emit. */
4478 :
4479 : static void
4480 1533029 : recompute_pool_offsets (struct rtx_constant_pool *pool)
4481 : {
4482 1533029 : class constant_descriptor_rtx *desc;
4483 1533029 : pool->offset = 0;
4484 :
4485 1533029 : for (desc = pool->first; desc ; desc = desc->next)
4486 0 : if (desc->mark)
4487 : {
4488 : /* Recalculate offset. */
4489 0 : unsigned int align = desc->align;
4490 0 : pool->offset += (align / BITS_PER_UNIT) - 1;
4491 0 : pool->offset &= ~ ((align / BITS_PER_UNIT) - 1);
4492 0 : desc->offset = pool->offset;
4493 0 : pool->offset += GET_MODE_SIZE (desc->mode);
4494 : }
4495 1533029 : }
4496 :
4497 : /* Mark all constants that are referenced by SYMBOL_REFs in X.
4498 : Emit referenced deferred strings. */
4499 :
4500 : static void
4501 39806260 : mark_constants_in_pattern (rtx_insn *insn)
4502 : {
4503 39806260 : subrtx_iterator::array_type array;
4504 266159626 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), ALL)
4505 : {
4506 226353366 : const_rtx x = *iter;
4507 226353366 : if (GET_CODE (x) == SYMBOL_REF)
4508 : {
4509 7891305 : if (CONSTANT_POOL_ADDRESS_P (x))
4510 : {
4511 783950 : class constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x);
4512 783950 : if (desc->mark == 0)
4513 : {
4514 260298 : desc->mark = 1;
4515 260298 : iter.substitute (desc->constant);
4516 : }
4517 : }
4518 7107355 : else if (TREE_CONSTANT_POOL_ADDRESS_P (x))
4519 : {
4520 761052 : tree decl = SYMBOL_REF_DECL (x);
4521 761052 : if (!TREE_ASM_WRITTEN (DECL_INITIAL (decl)))
4522 : {
4523 7987 : n_deferred_constants--;
4524 7987 : output_constant_def_contents (const_cast<rtx> (x));
4525 : }
4526 : }
4527 : }
4528 : }
4529 39806260 : }
4530 :
4531 : /* Look through appropriate parts of INSN, marking all entries in the
4532 : constant pool which are actually being used. Entries that are only
4533 : referenced by other constants are also marked as used. Emit
4534 : deferred strings that are used. */
4535 :
4536 : static void
4537 91262911 : mark_constants (rtx_insn *insn)
4538 : {
4539 91262911 : if (!INSN_P (insn))
4540 : return;
4541 :
4542 : /* Insns may appear inside a SEQUENCE. Only check the patterns of
4543 : insns, not any notes that may be attached. We don't want to mark
4544 : a constant just because it happens to appear in a REG_EQUIV note. */
4545 39806260 : if (rtx_sequence *seq = dyn_cast <rtx_sequence *> (PATTERN (insn)))
4546 : {
4547 0 : int i, n = seq->len ();
4548 0 : for (i = 0; i < n; ++i)
4549 : {
4550 0 : rtx_insn *subinsn = seq->insn (i);
4551 0 : if (INSN_P (subinsn))
4552 0 : mark_constants_in_pattern (subinsn);
4553 : }
4554 : }
4555 : else
4556 39806260 : mark_constants_in_pattern (insn);
4557 : }
4558 :
4559 : /* Look through the instructions for this function, and mark all the
4560 : entries in POOL which are actually being used. Emit deferred constants
4561 : which have indeed been used. */
4562 :
4563 : static void
4564 1533029 : mark_constant_pool (void)
4565 : {
4566 1533029 : rtx_insn *insn;
4567 :
4568 1533029 : if (!crtl->uses_const_pool && n_deferred_constants == 0)
4569 : return;
4570 :
4571 91447341 : for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
4572 91262911 : mark_constants (insn);
4573 : }
4574 :
4575 : /* Write all the constants in POOL. */
4576 :
4577 : static void
4578 1776554 : output_constant_pool_contents (struct rtx_constant_pool *pool)
4579 : {
4580 1776554 : class constant_descriptor_rtx *desc;
4581 :
4582 2139594 : for (desc = pool->first; desc ; desc = desc->next)
4583 363040 : if (desc->mark < 0)
4584 : {
4585 : #ifdef ASM_OUTPUT_DEF
4586 8729 : gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
4587 :
4588 8729 : const char *name = XSTR (desc->sym, 0);
4589 8729 : char label[256];
4590 8729 : char buffer[256 + 32];
4591 8729 : const char *p;
4592 :
4593 8729 : ASM_GENERATE_INTERNAL_LABEL (label, "LC", ~desc->mark);
4594 8729 : p = label;
4595 8729 : if (desc->offset)
4596 : {
4597 2881 : sprintf (buffer, "%s+" HOST_WIDE_INT_PRINT_DEC, p, desc->offset);
4598 2881 : p = buffer;
4599 : }
4600 8729 : ASM_OUTPUT_DEF (asm_out_file, name, p);
4601 : #else
4602 : gcc_unreachable ();
4603 : #endif
4604 : }
4605 354311 : else if (desc->mark)
4606 : {
4607 : /* If the constant is part of an object_block, make sure that
4608 : the constant has been positioned within its block, but do not
4609 : write out its definition yet. output_object_blocks will do
4610 : that later. */
4611 251568 : if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4612 251568 : && SYMBOL_REF_BLOCK (desc->sym))
4613 0 : place_block_symbol (desc->sym);
4614 : else
4615 : {
4616 251568 : switch_to_section (targetm.asm_out.select_rtx_section
4617 251568 : (desc->mode, desc->constant, desc->align));
4618 251568 : output_constant_pool_1 (desc, desc->align);
4619 : }
4620 : }
4621 1776554 : }
4622 :
4623 : struct constant_descriptor_rtx_data {
4624 : constant_descriptor_rtx *desc;
4625 : target_unit *bytes;
4626 : unsigned short size;
4627 : unsigned short offset;
4628 : unsigned int hash;
4629 : };
4630 :
4631 : /* qsort callback to sort constant_descriptor_rtx_data * vector by
4632 : decreasing size. */
4633 :
4634 : static int
4635 3861875 : constant_descriptor_rtx_data_cmp (const void *p1, const void *p2)
4636 : {
4637 3861875 : constant_descriptor_rtx_data *const data1
4638 : = *(constant_descriptor_rtx_data * const *) p1;
4639 3861875 : constant_descriptor_rtx_data *const data2
4640 : = *(constant_descriptor_rtx_data * const *) p2;
4641 3861875 : if (data1->size > data2->size)
4642 : return -1;
4643 3563980 : if (data1->size < data2->size)
4644 : return 1;
4645 3338864 : if (data1->hash < data2->hash)
4646 : return -1;
4647 1730162 : gcc_assert (data1->hash > data2->hash);
4648 : return 1;
4649 : }
4650 :
4651 : struct const_rtx_data_hasher : nofree_ptr_hash<constant_descriptor_rtx_data>
4652 : {
4653 : static hashval_t hash (constant_descriptor_rtx_data *);
4654 : static bool equal (constant_descriptor_rtx_data *,
4655 : constant_descriptor_rtx_data *);
4656 : };
4657 :
4658 : /* Hash and compare functions for const_rtx_data_htab. */
4659 :
4660 : hashval_t
4661 2208468 : const_rtx_data_hasher::hash (constant_descriptor_rtx_data *data)
4662 : {
4663 2208468 : return data->hash;
4664 : }
4665 :
4666 : bool
4667 2411518 : const_rtx_data_hasher::equal (constant_descriptor_rtx_data *x,
4668 : constant_descriptor_rtx_data *y)
4669 : {
4670 2411518 : if (x->hash != y->hash || x->size != y->size)
4671 : return false;
4672 159999 : unsigned int align1 = x->desc->align;
4673 159999 : unsigned int align2 = y->desc->align;
4674 159999 : unsigned int offset1 = (x->offset * BITS_PER_UNIT) & (align1 - 1);
4675 159999 : unsigned int offset2 = (y->offset * BITS_PER_UNIT) & (align2 - 1);
4676 159999 : if (offset1)
4677 78493 : align1 = least_bit_hwi (offset1);
4678 159999 : if (offset2)
4679 113459 : align2 = least_bit_hwi (offset2);
4680 159999 : if (align2 > align1)
4681 : return false;
4682 136965 : if (memcmp (x->bytes, y->bytes, x->size * sizeof (target_unit)) != 0)
4683 0 : return false;
4684 : return true;
4685 : }
4686 :
4687 : /* Attempt to optimize constant pool POOL. If it contains both CONST_VECTOR
4688 : constants and scalar constants with the values of CONST_VECTOR elements,
4689 : try to alias the scalar constants with the CONST_VECTOR elements. */
4690 :
4691 : static void
4692 156566 : optimize_constant_pool (struct rtx_constant_pool *pool)
4693 : {
4694 156566 : auto_vec<target_unit, 128> buffer;
4695 156566 : auto_vec<constant_descriptor_rtx_data *, 128> vec;
4696 156566 : object_allocator<constant_descriptor_rtx_data>
4697 156566 : data_pool ("constant_descriptor_rtx_data_pool");
4698 156566 : int idx = 0;
4699 156566 : size_t size = 0;
4700 476441 : for (constant_descriptor_rtx *desc = pool->first; desc; desc = desc->next)
4701 319875 : if (desc->mark > 0
4702 319875 : && ! (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym)
4703 0 : && SYMBOL_REF_BLOCK (desc->sym)))
4704 : {
4705 220808 : buffer.truncate (0);
4706 441616 : buffer.reserve (GET_MODE_SIZE (desc->mode));
4707 220808 : if (native_encode_rtx (desc->mode, desc->constant, buffer, 0,
4708 441616 : GET_MODE_SIZE (desc->mode)))
4709 : {
4710 192565 : constant_descriptor_rtx_data *data = data_pool.allocate ();
4711 192565 : data->desc = desc;
4712 192565 : data->bytes = NULL;
4713 192565 : data->size = GET_MODE_SIZE (desc->mode);
4714 192565 : data->offset = 0;
4715 192565 : data->hash = idx++;
4716 192565 : size += data->size;
4717 192565 : vec.safe_push (data);
4718 : }
4719 : }
4720 156566 : if (idx)
4721 : {
4722 29246 : vec.qsort (constant_descriptor_rtx_data_cmp);
4723 29246 : unsigned min_size = vec.last ()->size;
4724 29246 : target_unit *bytes = XNEWVEC (target_unit, size);
4725 29246 : unsigned int i;
4726 29246 : constant_descriptor_rtx_data *data;
4727 29246 : hash_table<const_rtx_data_hasher> * htab
4728 29246 : = new hash_table<const_rtx_data_hasher> (31);
4729 29246 : size = 0;
4730 280303 : FOR_EACH_VEC_ELT (vec, i, data)
4731 : {
4732 192565 : buffer.truncate (0);
4733 192565 : native_encode_rtx (data->desc->mode, data->desc->constant,
4734 192565 : buffer, 0, data->size);
4735 192565 : memcpy (bytes + size, buffer.address (), data->size);
4736 192565 : data->bytes = bytes + size;
4737 385130 : data->hash = iterative_hash (data->bytes,
4738 192565 : data->size * sizeof (target_unit), 0);
4739 192565 : size += data->size;
4740 192565 : constant_descriptor_rtx_data **slot
4741 192565 : = htab->find_slot_with_hash (data, data->hash, INSERT);
4742 192565 : if (*slot)
4743 : {
4744 8729 : data->desc->mark = ~(*slot)->desc->labelno;
4745 8729 : data->desc->offset = (*slot)->offset;
4746 : }
4747 : else
4748 : {
4749 183836 : unsigned int sz = 1 << floor_log2 (data->size);
4750 :
4751 183836 : *slot = data;
4752 269658 : for (sz >>= 1; sz >= min_size; sz >>= 1)
4753 381809 : for (unsigned off = 0; off + sz <= data->size; off += sz)
4754 : {
4755 295987 : constant_descriptor_rtx_data tmp;
4756 295987 : tmp.desc = data->desc;
4757 295987 : tmp.bytes = data->bytes + off;
4758 295987 : tmp.size = sz;
4759 295987 : tmp.offset = off;
4760 295987 : tmp.hash = iterative_hash (tmp.bytes,
4761 : sz * sizeof (target_unit), 0);
4762 295987 : slot = htab->find_slot_with_hash (&tmp, tmp.hash, INSERT);
4763 295987 : if (*slot == NULL)
4764 : {
4765 167751 : *slot = data_pool.allocate ();
4766 167751 : **slot = tmp;
4767 : }
4768 : }
4769 : }
4770 : }
4771 29246 : delete htab;
4772 29246 : XDELETE (bytes);
4773 : }
4774 156566 : data_pool.release ();
4775 156566 : }
4776 :
4777 : /* Mark all constants that are used in the current function, then write
4778 : out the function's private constant pool. */
4779 :
4780 : static void
4781 1533029 : output_constant_pool (const char *fnname ATTRIBUTE_UNUSED,
4782 : tree fndecl ATTRIBUTE_UNUSED)
4783 : {
4784 1533029 : struct rtx_constant_pool *pool = crtl->varasm.pool;
4785 :
4786 : /* It is possible for gcc to call force_const_mem and then to later
4787 : discard the instructions which refer to the constant. In such a
4788 : case we do not need to output the constant. */
4789 1533029 : mark_constant_pool ();
4790 :
4791 : /* Having marked the constant pool entries we'll actually emit, we
4792 : now need to rebuild the offset information, which may have become
4793 : stale. */
4794 1533029 : recompute_pool_offsets (pool);
4795 :
4796 : #ifdef ASM_OUTPUT_POOL_PROLOGUE
4797 : ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset);
4798 : #endif
4799 :
4800 1533029 : output_constant_pool_contents (pool);
4801 :
4802 : #ifdef ASM_OUTPUT_POOL_EPILOGUE
4803 : ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset);
4804 : #endif
4805 1533029 : }
4806 :
4807 : /* Write the contents of the shared constant pool. */
4808 :
4809 : void
4810 243525 : output_shared_constant_pool (void)
4811 : {
4812 243525 : if (optimize
4813 : && TARGET_SUPPORTS_ALIASES)
4814 156566 : optimize_constant_pool (shared_constant_pool);
4815 :
4816 243525 : output_constant_pool_contents (shared_constant_pool);
4817 243525 : }
4818 :
4819 : /* Determine what kind of relocations EXP may need. */
4820 :
4821 : int
4822 35636774 : compute_reloc_for_constant (tree exp)
4823 : {
4824 38122855 : int reloc = 0, reloc2;
4825 38122855 : tree tem;
4826 :
4827 38122855 : switch (TREE_CODE (exp))
4828 : {
4829 10120175 : case ADDR_EXPR:
4830 10120175 : case FDESC_EXPR:
4831 : /* Go inside any operations that get_inner_reference can handle and see
4832 : if what's inside is a constant: no need to do anything here for
4833 : addresses of variables or functions. */
4834 10194781 : for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4835 74606 : tem = TREE_OPERAND (tem, 0))
4836 : ;
4837 :
4838 10120175 : if (TREE_CODE (tem) == MEM_REF
4839 10120175 : && TREE_CODE (TREE_OPERAND (tem, 0)) == ADDR_EXPR)
4840 : {
4841 59614 : reloc = compute_reloc_for_constant (TREE_OPERAND (tem, 0));
4842 59614 : break;
4843 : }
4844 :
4845 10060561 : if (!targetm.binds_local_p (tem))
4846 : reloc |= 2;
4847 : else
4848 7730599 : reloc |= 1;
4849 : break;
4850 :
4851 19441 : case PLUS_EXPR:
4852 19441 : case POINTER_PLUS_EXPR:
4853 19441 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4854 19441 : reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4855 19441 : break;
4856 :
4857 26 : case MINUS_EXPR:
4858 26 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4859 26 : reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1));
4860 : /* The difference of two local labels is computable at link time. */
4861 26 : if (reloc == 1 && reloc2 == 1)
4862 : reloc = 0;
4863 : else
4864 0 : reloc |= reloc2;
4865 : break;
4866 :
4867 2426467 : CASE_CONVERT:
4868 2426467 : case VIEW_CONVERT_EXPR:
4869 2426467 : reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0));
4870 2426467 : break;
4871 :
4872 : case CONSTRUCTOR:
4873 : {
4874 : unsigned HOST_WIDE_INT idx;
4875 37762078 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4876 29787510 : if (tem != 0)
4877 29787510 : reloc |= compute_reloc_for_constant (tem);
4878 : }
4879 : break;
4880 :
4881 : default:
4882 : break;
4883 : }
4884 35636774 : return reloc;
4885 : }
4886 :
4887 : /* Find all the constants whose addresses are referenced inside of EXP,
4888 : and make sure assembler code with a label has been output for each one.
4889 : Indicate whether an ADDR_EXPR has been encountered. */
4890 :
4891 : static void
4892 22794567 : output_addressed_constants (tree exp, int defer)
4893 : {
4894 23289917 : tree tem;
4895 :
4896 23289917 : switch (TREE_CODE (exp))
4897 : {
4898 4590288 : case ADDR_EXPR:
4899 4590288 : case FDESC_EXPR:
4900 : /* Go inside any operations that get_inner_reference can handle and see
4901 : if what's inside is a constant: no need to do anything here for
4902 : addresses of variables or functions. */
4903 4665107 : for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem);
4904 74819 : tem = TREE_OPERAND (tem, 0))
4905 : ;
4906 :
4907 : /* If we have an initialized CONST_DECL, retrieve the initializer. */
4908 4590288 : if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem))
4909 0 : tem = DECL_INITIAL (tem);
4910 :
4911 4590288 : if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR)
4912 990389 : output_constant_def (tem, defer);
4913 :
4914 4590288 : if (TREE_CODE (tem) == MEM_REF)
4915 55051 : output_addressed_constants (TREE_OPERAND (tem, 0), defer);
4916 : break;
4917 :
4918 16983 : case PLUS_EXPR:
4919 16983 : case POINTER_PLUS_EXPR:
4920 16983 : case MINUS_EXPR:
4921 16983 : output_addressed_constants (TREE_OPERAND (exp, 1), defer);
4922 440299 : gcc_fallthrough ();
4923 :
4924 440299 : CASE_CONVERT:
4925 440299 : case VIEW_CONVERT_EXPR:
4926 440299 : output_addressed_constants (TREE_OPERAND (exp, 0), defer);
4927 440299 : break;
4928 :
4929 : case CONSTRUCTOR:
4930 : {
4931 : unsigned HOST_WIDE_INT idx;
4932 19590750 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem)
4933 15473568 : if (tem != 0)
4934 15473568 : output_addressed_constants (tem, defer);
4935 : }
4936 : break;
4937 :
4938 : default:
4939 : break;
4940 : }
4941 22794567 : }
4942 :
4943 : /* Whether a constructor CTOR is a valid static constant initializer if all
4944 : its elements are. This used to be internal to initializer_constant_valid_p
4945 : and has been exposed to let other functions like categorize_ctor_elements
4946 : evaluate the property while walking a constructor for other purposes. */
4947 :
4948 : bool
4949 14659193 : constructor_static_from_elts_p (const_tree ctor)
4950 : {
4951 14659193 : return (TREE_CONSTANT (ctor)
4952 14659193 : && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE
4953 14008398 : || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE
4954 1489309 : || TREE_CODE (TREE_TYPE (ctor)) == ARRAY_TYPE));
4955 : }
4956 :
4957 : static tree initializer_constant_valid_p_1 (tree value, tree endtype,
4958 : tree *cache);
4959 :
4960 : /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR,
4961 : PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE
4962 : which are valid when ENDTYPE is an integer of any size; in
4963 : particular, this does not accept a pointer minus a constant. This
4964 : returns null_pointer_node if the VALUE is an absolute constant
4965 : which can be used to initialize a static variable. Otherwise it
4966 : returns NULL. */
4967 :
4968 : static tree
4969 1128368 : narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4970 : {
4971 1128368 : tree op0, op1;
4972 :
4973 1128368 : if (!INTEGRAL_TYPE_P (endtype))
4974 : return NULL_TREE;
4975 :
4976 1031596 : op0 = TREE_OPERAND (value, 0);
4977 1031596 : op1 = TREE_OPERAND (value, 1);
4978 :
4979 : /* Like STRIP_NOPS except allow the operand mode to widen. This
4980 : works around a feature of fold that simplifies (int)(p1 - p2) to
4981 : ((int)p1 - (int)p2) under the theory that the narrower operation
4982 : is cheaper. */
4983 :
4984 2046811 : while (CONVERT_EXPR_P (op0)
4985 2388259 : || TREE_CODE (op0) == NON_LVALUE_EXPR)
4986 : {
4987 377064 : tree inner = TREE_OPERAND (op0, 0);
4988 754128 : if (inner == error_mark_node
4989 377064 : || ! INTEGRAL_TYPE_P (TREE_TYPE (op0))
4990 372683 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op0)))
4991 372683 : || ! INTEGRAL_TYPE_P (TREE_TYPE (inner))
4992 372527 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4993 749591 : || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0)))
4994 771054 : > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner)))))
4995 : break;
4996 : op0 = inner;
4997 : }
4998 :
4999 1021077 : while (CONVERT_EXPR_P (op1)
5000 2256259 : || TREE_CODE (op1) == NON_LVALUE_EXPR)
5001 : {
5002 252899 : tree inner = TREE_OPERAND (op1, 0);
5003 505798 : if (inner == error_mark_node
5004 252899 : || ! INTEGRAL_TYPE_P (TREE_TYPE (op1))
5005 252773 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op1)))
5006 252773 : || ! INTEGRAL_TYPE_P (TREE_TYPE (inner))
5007 252687 : || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
5008 505586 : || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1)))
5009 535611 : > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner)))))
5010 : break;
5011 : op1 = inner;
5012 : }
5013 :
5014 1031596 : op0 = initializer_constant_valid_p_1 (op0, endtype, cache);
5015 1031596 : if (!op0)
5016 : return NULL_TREE;
5017 :
5018 927 : op1 = initializer_constant_valid_p_1 (op1, endtype,
5019 : cache ? cache + 2 : NULL);
5020 : /* Both initializers must be known. */
5021 927 : if (op1)
5022 : {
5023 201 : if (op0 == op1
5024 30 : && (op0 == null_pointer_node
5025 11 : || TREE_CODE (value) == MINUS_EXPR))
5026 : return null_pointer_node;
5027 :
5028 : /* Support differences between labels. */
5029 182 : if (TREE_CODE (op0) == LABEL_DECL
5030 169 : && TREE_CODE (op1) == LABEL_DECL)
5031 169 : return null_pointer_node;
5032 :
5033 13 : if (TREE_CODE (op0) == STRING_CST
5034 0 : && TREE_CODE (op1) == STRING_CST
5035 13 : && operand_equal_p (op0, op1, 1))
5036 0 : return null_pointer_node;
5037 : }
5038 :
5039 : return NULL_TREE;
5040 : }
5041 :
5042 : /* Helper function of initializer_constant_valid_p.
5043 : Return nonzero if VALUE is a valid constant-valued expression
5044 : for use in initializing a static variable; one that can be an
5045 : element of a "constant" initializer.
5046 :
5047 : Return null_pointer_node if the value is absolute;
5048 : if it is relocatable, return the variable that determines the relocation.
5049 : We assume that VALUE has been folded as much as possible;
5050 : therefore, we do not need to check for such things as
5051 : arithmetic-combinations of integers.
5052 :
5053 : Use CACHE (pointer to 2 tree values) for caching if non-NULL. */
5054 :
5055 : static tree
5056 1378539361 : initializer_constant_valid_p_1 (tree value, tree endtype, tree *cache)
5057 : {
5058 1433657859 : tree ret;
5059 :
5060 1433657859 : switch (TREE_CODE (value))
5061 : {
5062 13096328 : case CONSTRUCTOR:
5063 13096328 : if (constructor_static_from_elts_p (value))
5064 : {
5065 13085030 : unsigned HOST_WIDE_INT idx;
5066 13085030 : tree elt;
5067 13085030 : bool absolute = true;
5068 :
5069 13085030 : if (cache && cache[0] == value)
5070 0 : return cache[1];
5071 121992563 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
5072 : {
5073 108907937 : tree reloc;
5074 108907937 : reloc = initializer_constant_valid_p_1 (elt, TREE_TYPE (elt),
5075 : NULL);
5076 108907937 : if (!reloc
5077 : /* An absolute value is required with reverse SSO. */
5078 108907937 : || (reloc != null_pointer_node
5079 10172068 : && TYPE_REVERSE_STORAGE_ORDER (TREE_TYPE (value))
5080 1 : && !AGGREGATE_TYPE_P (TREE_TYPE (elt))))
5081 : {
5082 404 : if (cache)
5083 : {
5084 0 : cache[0] = value;
5085 0 : cache[1] = NULL_TREE;
5086 : }
5087 : return NULL_TREE;
5088 : }
5089 108907533 : if (reloc != null_pointer_node)
5090 10172067 : absolute = false;
5091 : }
5092 : /* For a non-absolute relocation, there is no single
5093 : variable that can be "the variable that determines the
5094 : relocation." */
5095 13084626 : if (cache)
5096 : {
5097 0 : cache[0] = value;
5098 0 : cache[1] = absolute ? null_pointer_node : error_mark_node;
5099 : }
5100 13084626 : return absolute ? null_pointer_node : error_mark_node;
5101 : }
5102 :
5103 11298 : return TREE_STATIC (value) ? null_pointer_node : NULL_TREE;
5104 :
5105 1286785862 : case INTEGER_CST:
5106 1286785862 : case VECTOR_CST:
5107 1286785862 : case REAL_CST:
5108 1286785862 : case FIXED_CST:
5109 1286785862 : case STRING_CST:
5110 1286785862 : case COMPLEX_CST:
5111 1286785862 : case RAW_DATA_CST:
5112 1286785862 : return null_pointer_node;
5113 :
5114 53417836 : case ADDR_EXPR:
5115 53417836 : case FDESC_EXPR:
5116 53417836 : {
5117 53417836 : tree op0 = staticp (TREE_OPERAND (value, 0));
5118 53417836 : if (op0)
5119 : {
5120 : /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out
5121 : to be a constant, this is old-skool offsetof-like nonsense. */
5122 50612286 : if (TREE_CODE (op0) == INDIRECT_REF
5123 50612286 : && TREE_CONSTANT (TREE_OPERAND (op0, 0)))
5124 46 : return null_pointer_node;
5125 : /* Taking the address of a nested function involves a trampoline,
5126 : unless we don't need or want one. */
5127 50612240 : if (TREE_CODE (op0) == FUNCTION_DECL
5128 9316609 : && DECL_STATIC_CHAIN (op0)
5129 50612262 : && !TREE_NO_TRAMPOLINE (value))
5130 : return NULL_TREE;
5131 : /* "&{...}" requires a temporary to hold the constructed
5132 : object. */
5133 50612218 : if (TREE_CODE (op0) == CONSTRUCTOR)
5134 0 : return NULL_TREE;
5135 : }
5136 : return op0;
5137 : }
5138 :
5139 1174226 : case NON_LVALUE_EXPR:
5140 1174226 : return initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5141 1174226 : endtype, cache);
5142 :
5143 2298624 : case VIEW_CONVERT_EXPR:
5144 2298624 : {
5145 2298624 : tree src = TREE_OPERAND (value, 0);
5146 2298624 : tree src_type = TREE_TYPE (src);
5147 2298624 : tree dest_type = TREE_TYPE (value);
5148 :
5149 : /* Allow view-conversions from aggregate to non-aggregate type only
5150 : if the bit pattern is fully preserved afterwards; otherwise, the
5151 : RTL expander won't be able to apply a subsequent transformation
5152 : to the underlying constructor. */
5153 2298624 : if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type))
5154 : {
5155 0 : if (TYPE_MODE (endtype) == TYPE_MODE (dest_type))
5156 : return initializer_constant_valid_p_1 (src, endtype, cache);
5157 : else
5158 : return NULL_TREE;
5159 : }
5160 :
5161 : /* Allow all other kinds of view-conversion. */
5162 : return initializer_constant_valid_p_1 (src, endtype, cache);
5163 : }
5164 :
5165 52184650 : CASE_CONVERT:
5166 52184650 : {
5167 52184650 : tree src = TREE_OPERAND (value, 0);
5168 52184650 : tree src_type = TREE_TYPE (src);
5169 52184650 : tree dest_type = TREE_TYPE (value);
5170 :
5171 : /* Allow conversions between pointer types and offset types. */
5172 52184650 : if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type))
5173 2656680 : || (TREE_CODE (dest_type) == OFFSET_TYPE
5174 85 : && TREE_CODE (src_type) == OFFSET_TYPE))
5175 : return initializer_constant_valid_p_1 (src, endtype, cache);
5176 :
5177 : /* Allow length-preserving conversions between integer types and
5178 : floating-point types. */
5179 2394293 : if (((INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type))
5180 334567 : || (SCALAR_FLOAT_TYPE_P (dest_type)
5181 66288 : && SCALAR_FLOAT_TYPE_P (src_type)))
5182 5044947 : && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type)))
5183 : return initializer_constant_valid_p_1 (src, endtype, cache);
5184 :
5185 : /* Allow conversions between other integer types only if
5186 : explicit value. Don't allow sign-extension to a type larger
5187 : than word and pointer, there aren't relocations that would
5188 : allow to sign extend it to a wider type. */
5189 729108 : if (INTEGRAL_TYPE_P (dest_type)
5190 530467 : && INTEGRAL_TYPE_P (src_type)
5191 1187328 : && (TYPE_UNSIGNED (src_type)
5192 141453 : || TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)
5193 80668 : || TYPE_PRECISION (dest_type) <= BITS_PER_WORD
5194 757 : || TYPE_PRECISION (dest_type) <= POINTER_SIZE))
5195 : {
5196 457824 : tree inner = initializer_constant_valid_p_1 (src, endtype, cache);
5197 457824 : if (inner == null_pointer_node)
5198 377 : return null_pointer_node;
5199 : break;
5200 : }
5201 :
5202 : /* Allow (int) &foo provided int is as wide as a pointer. */
5203 72643 : if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)
5204 343516 : && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)))
5205 : return initializer_constant_valid_p_1 (src, endtype, cache);
5206 :
5207 : /* Likewise conversions from int to pointers, but also allow
5208 : conversions from 0. */
5209 199238 : if ((POINTER_TYPE_P (dest_type)
5210 121145 : || TREE_CODE (dest_type) == OFFSET_TYPE)
5211 78111 : && INTEGRAL_TYPE_P (src_type))
5212 : {
5213 571 : if (TREE_CODE (src) == INTEGER_CST
5214 571 : && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))
5215 16 : return null_pointer_node;
5216 555 : if (integer_zerop (src))
5217 0 : return null_pointer_node;
5218 555 : else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type))
5219 : return initializer_constant_valid_p_1 (src, endtype, cache);
5220 : }
5221 :
5222 : /* Allow conversions to struct or union types if the value
5223 : inside is okay. */
5224 198667 : if (TREE_CODE (dest_type) == RECORD_TYPE
5225 198667 : || TREE_CODE (dest_type) == UNION_TYPE)
5226 : return initializer_constant_valid_p_1 (src, endtype, cache);
5227 : }
5228 : break;
5229 :
5230 7347364 : case POINTER_PLUS_EXPR:
5231 7347364 : case PLUS_EXPR:
5232 : /* Any valid floating-point constants will have been folded by now;
5233 : with -frounding-math we hit this with addition of two constants. */
5234 7347364 : if (TREE_CODE (endtype) == REAL_TYPE)
5235 : return NULL_TREE;
5236 6351493 : if (cache && cache[0] == value)
5237 133138 : return cache[1];
5238 6218355 : if (! INTEGRAL_TYPE_P (endtype)
5239 742863 : || ! INTEGRAL_TYPE_P (TREE_TYPE (value))
5240 6960554 : || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
5241 : {
5242 6199729 : tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
5243 6199729 : tree valid0
5244 6199729 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5245 : endtype, ncache);
5246 6199729 : tree valid1
5247 6199729 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
5248 : endtype, ncache + 2);
5249 : /* If either term is absolute, use the other term's relocation. */
5250 6199729 : if (valid0 == null_pointer_node)
5251 : ret = valid1;
5252 6198246 : else if (valid1 == null_pointer_node)
5253 : ret = valid0;
5254 : /* Support narrowing pointer differences. */
5255 : else
5256 442776 : ret = narrowing_initializer_constant_valid_p (value, endtype,
5257 : ncache);
5258 : }
5259 : else
5260 : /* Support narrowing pointer differences. */
5261 18626 : ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
5262 6218355 : if (cache)
5263 : {
5264 148092 : cache[0] = value;
5265 148092 : cache[1] = ret;
5266 : }
5267 : return ret;
5268 :
5269 1533408 : case POINTER_DIFF_EXPR:
5270 1533408 : case MINUS_EXPR:
5271 1533408 : if (TREE_CODE (endtype) == REAL_TYPE)
5272 : return NULL_TREE;
5273 1031642 : if (cache && cache[0] == value)
5274 160310 : return cache[1];
5275 871332 : if (! INTEGRAL_TYPE_P (endtype)
5276 871237 : || ! INTEGRAL_TYPE_P (TREE_TYPE (value))
5277 1742566 : || TYPE_PRECISION (endtype) >= TYPE_PRECISION (TREE_TYPE (value)))
5278 : {
5279 837210 : tree ncache[4] = { NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE };
5280 837210 : tree valid0
5281 837210 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 0),
5282 : endtype, ncache);
5283 837210 : tree valid1
5284 837210 : = initializer_constant_valid_p_1 (TREE_OPERAND (value, 1),
5285 : endtype, ncache + 2);
5286 : /* Win if second argument is absolute. */
5287 837210 : if (valid1 == null_pointer_node)
5288 : ret = valid0;
5289 : /* Win if both arguments have the same relocation.
5290 : Then the value is absolute. */
5291 632844 : else if (valid0 == valid1 && valid0 != 0)
5292 : ret = null_pointer_node;
5293 : /* Since GCC guarantees that string constants are unique in the
5294 : generated code, a subtraction between two copies of the same
5295 : constant string is absolute. */
5296 794 : else if (valid0 && TREE_CODE (valid0) == STRING_CST
5297 0 : && valid1 && TREE_CODE (valid1) == STRING_CST
5298 632844 : && operand_equal_p (valid0, valid1, 1))
5299 0 : ret = null_pointer_node;
5300 : /* Support narrowing differences. */
5301 : else
5302 632844 : ret = narrowing_initializer_constant_valid_p (value, endtype,
5303 : ncache);
5304 : }
5305 : else
5306 : /* Support narrowing differences. */
5307 34122 : ret = narrowing_initializer_constant_valid_p (value, endtype, NULL);
5308 871332 : if (cache)
5309 : {
5310 162198 : cache[0] = value;
5311 162198 : cache[1] = ret;
5312 : }
5313 : return ret;
5314 :
5315 : default:
5316 : break;
5317 : }
5318 :
5319 : return NULL_TREE;
5320 : }
5321 :
5322 : /* Return nonzero if VALUE is a valid constant-valued expression
5323 : for use in initializing a static variable; one that can be an
5324 : element of a "constant" initializer.
5325 :
5326 : Return null_pointer_node if the value is absolute;
5327 : if it is relocatable, return the variable that determines the relocation.
5328 : We assume that VALUE has been folded as much as possible;
5329 : therefore, we do not need to check for such things as
5330 : arithmetic-combinations of integers. */
5331 : tree
5332 1254067199 : initializer_constant_valid_p (tree value, tree endtype, bool reverse)
5333 : {
5334 1254067199 : tree reloc = initializer_constant_valid_p_1 (value, endtype, NULL);
5335 :
5336 : /* An absolute value is required with reverse storage order. */
5337 1254067199 : if (reloc
5338 1235621370 : && reloc != null_pointer_node
5339 47256395 : && reverse
5340 1 : && !AGGREGATE_TYPE_P (endtype)
5341 1 : && !VECTOR_TYPE_P (endtype))
5342 1254067199 : reloc = NULL_TREE;
5343 :
5344 1254067199 : return reloc;
5345 : }
5346 :
5347 : /* Return true if VALUE is a valid constant-valued expression
5348 : for use in initializing a static bit-field; one that can be
5349 : an element of a "constant" initializer. */
5350 :
5351 : bool
5352 885 : initializer_constant_valid_for_bitfield_p (const_tree value)
5353 : {
5354 : /* For bitfields we support integer constants or possibly nested aggregates
5355 : of such. */
5356 885 : switch (TREE_CODE (value))
5357 : {
5358 : case CONSTRUCTOR:
5359 : {
5360 : unsigned HOST_WIDE_INT idx;
5361 : const_tree elt;
5362 :
5363 957 : FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt)
5364 696 : if (!initializer_constant_valid_for_bitfield_p (elt))
5365 : return false;
5366 : return true;
5367 : }
5368 :
5369 : case INTEGER_CST:
5370 : case REAL_CST:
5371 : return true;
5372 :
5373 0 : case VIEW_CONVERT_EXPR:
5374 0 : case NON_LVALUE_EXPR:
5375 0 : return
5376 0 : initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0));
5377 :
5378 : default:
5379 : break;
5380 : }
5381 :
5382 : return false;
5383 : }
5384 :
5385 : /* Check if a STRING_CST fits into the field.
5386 : Tolerate only the case when the NUL termination
5387 : does not fit into the field. */
5388 :
5389 : static bool
5390 1343463 : check_string_literal (tree string, unsigned HOST_WIDE_INT size)
5391 : {
5392 1343463 : tree type = TREE_TYPE (string);
5393 1343463 : tree eltype = TREE_TYPE (type);
5394 1343463 : unsigned HOST_WIDE_INT elts = tree_to_uhwi (TYPE_SIZE_UNIT (eltype));
5395 1343463 : unsigned HOST_WIDE_INT mem_size = tree_to_uhwi (TYPE_SIZE_UNIT (type));
5396 1343463 : int len = TREE_STRING_LENGTH (string);
5397 :
5398 1343463 : if (elts != 1 && elts != 2 && elts != 4)
5399 : return false;
5400 1343463 : if (len < 0 || len % elts != 0)
5401 : return false;
5402 1343463 : if (size < (unsigned)len)
5403 : return false;
5404 1343463 : if (mem_size != size)
5405 0 : return false;
5406 : return true;
5407 : }
5408 :
5409 : /* output_constructor outer state of relevance in recursive calls, typically
5410 : for nested aggregate bitfields. */
5411 :
5412 : struct oc_outer_state {
5413 : unsigned int bit_offset; /* current position in ... */
5414 : int byte; /* ... the outer byte buffer. */
5415 : };
5416 :
5417 : static unsigned HOST_WIDE_INT
5418 : output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int, bool,
5419 : oc_outer_state *);
5420 :
5421 : /* Output assembler code for constant EXP, with no label.
5422 : This includes the pseudo-op such as ".int" or ".byte", and a newline.
5423 : Assumes output_addressed_constants has been done on EXP already.
5424 :
5425 : Generate at least SIZE bytes of assembler data, padding at the end
5426 : with zeros if necessary. SIZE must always be specified. The returned
5427 : value is the actual number of bytes of assembler data generated, which
5428 : may be bigger than SIZE if the object contains a variable length field.
5429 :
5430 : SIZE is important for structure constructors,
5431 : since trailing members may have been omitted from the constructor.
5432 : It is also important for initialization of arrays from string constants
5433 : since the full length of the string constant might not be wanted.
5434 : It is also needed for initialization of unions, where the initializer's
5435 : type is just one member, and that may not be as long as the union.
5436 :
5437 : There a case in which we would fail to output exactly SIZE bytes:
5438 : for a structure constructor that wants to produce more than SIZE bytes.
5439 : But such constructors will never be generated for any possible input.
5440 :
5441 : ALIGN is the alignment of the data in bits.
5442 :
5443 : If REVERSE is true, EXP is output in reverse storage order. */
5444 :
5445 : static unsigned HOST_WIDE_INT
5446 18056600 : output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align,
5447 : bool reverse, bool merge_strings)
5448 : {
5449 18056600 : enum tree_code code;
5450 18056600 : unsigned HOST_WIDE_INT thissize;
5451 18056600 : rtx cst;
5452 :
5453 18056600 : if (size == 0 || flag_syntax_only)
5454 : return size;
5455 :
5456 : /* See if we're trying to initialize a pointer in a non-default mode
5457 : to the address of some declaration somewhere. If the target says
5458 : the mode is valid for pointers, assume the target has a way of
5459 : resolving it. */
5460 18056352 : if (TREE_CODE (exp) == NOP_EXPR
5461 192 : && POINTER_TYPE_P (TREE_TYPE (exp))
5462 18056498 : && targetm.addr_space.valid_pointer_mode
5463 18056352 : (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp)),
5464 146 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
5465 : {
5466 146 : tree saved_type = TREE_TYPE (exp);
5467 :
5468 : /* Peel off any intermediate conversions-to-pointer for valid
5469 : pointer modes. */
5470 146 : while (TREE_CODE (exp) == NOP_EXPR
5471 146 : && POINTER_TYPE_P (TREE_TYPE (exp))
5472 438 : && targetm.addr_space.valid_pointer_mode
5473 146 : (SCALAR_INT_TYPE_MODE (TREE_TYPE (exp)),
5474 146 : TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (exp)))))
5475 146 : exp = TREE_OPERAND (exp, 0);
5476 :
5477 : /* If what we're left with is the address of something, we can
5478 : convert the address to the final type and output it that
5479 : way. */
5480 146 : if (TREE_CODE (exp) == ADDR_EXPR)
5481 11 : exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0));
5482 : /* Likewise for constant ints. */
5483 135 : else if (TREE_CODE (exp) == INTEGER_CST)
5484 135 : exp = fold_convert (saved_type, exp);
5485 :
5486 : }
5487 :
5488 : /* Eliminate any conversions since we'll be outputting the underlying
5489 : constant. */
5490 18059621 : while (CONVERT_EXPR_P (exp)
5491 18059582 : || TREE_CODE (exp) == NON_LVALUE_EXPR
5492 36119249 : || TREE_CODE (exp) == VIEW_CONVERT_EXPR)
5493 : {
5494 3321 : HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp));
5495 3321 : HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0)));
5496 :
5497 : /* Make sure eliminating the conversion is really a no-op, except with
5498 : VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and
5499 : union types to allow for Ada unchecked unions. */
5500 3321 : if (type_size > op_size
5501 6 : && TREE_CODE (exp) != VIEW_CONVERT_EXPR
5502 3327 : && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE)
5503 : /* Keep the conversion. */
5504 : break;
5505 : else
5506 3315 : exp = TREE_OPERAND (exp, 0);
5507 : }
5508 :
5509 18056352 : code = TREE_CODE (TREE_TYPE (exp));
5510 18056352 : thissize = int_size_in_bytes (TREE_TYPE (exp));
5511 :
5512 : /* Allow a constructor with no elements for any data type.
5513 : This means to fill the space with zeros. */
5514 18056352 : if (TREE_CODE (exp) == CONSTRUCTOR
5515 18056352 : && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp)))
5516 : {
5517 3099 : assemble_zeros (size);
5518 3099 : return size;
5519 : }
5520 :
5521 18053253 : if (TREE_CODE (exp) == FDESC_EXPR)
5522 : {
5523 : #ifdef ASM_OUTPUT_FDESC
5524 : HOST_WIDE_INT part = tree_to_shwi (TREE_OPERAND (exp, 1));
5525 : tree decl = TREE_OPERAND (exp, 0);
5526 : ASM_OUTPUT_FDESC (asm_out_file, decl, part);
5527 : #else
5528 0 : gcc_unreachable ();
5529 : #endif
5530 : return size;
5531 : }
5532 :
5533 : /* Now output the underlying data. If we've handling the padding, return.
5534 : Otherwise, break and ensure SIZE is the size written. */
5535 18053253 : switch (code)
5536 : {
5537 21577 : case ENUMERAL_TYPE:
5538 21577 : if (BITINT_TYPE_P (TREE_TYPE (exp)))
5539 14 : goto do_bitint;
5540 : /* FALLTHRU */
5541 12268835 : case BOOLEAN_TYPE:
5542 12268835 : case INTEGER_TYPE:
5543 12268835 : case POINTER_TYPE:
5544 12268835 : case REFERENCE_TYPE:
5545 12268835 : case OFFSET_TYPE:
5546 12268835 : case FIXED_POINT_TYPE:
5547 12268835 : case NULLPTR_TYPE:
5548 12268835 : cst = expand_expr (exp, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
5549 12268835 : if (reverse)
5550 558 : cst = flip_storage_order (TYPE_MODE (TREE_TYPE (exp)), cst);
5551 12268835 : if (!assemble_integer (cst, MIN (size, thissize), align, 0))
5552 0 : error ("initializer for integer/fixed-point value is too complicated");
5553 : break;
5554 :
5555 601201 : case REAL_TYPE:
5556 601201 : gcc_assert (size == thissize);
5557 601201 : if (TREE_CODE (exp) != REAL_CST)
5558 1 : error ("initializer for floating value is not a floating constant");
5559 : else
5560 601200 : assemble_real (TREE_REAL_CST (exp),
5561 601200 : SCALAR_FLOAT_TYPE_MODE (TREE_TYPE (exp)),
5562 : align, reverse);
5563 : break;
5564 :
5565 12138 : case COMPLEX_TYPE:
5566 12138 : output_constant (TREE_REALPART (exp), thissize / 2, align,
5567 : reverse, false);
5568 12138 : output_constant (TREE_IMAGPART (exp), thissize / 2,
5569 : min_align (align, BITS_PER_UNIT * (thissize / 2)),
5570 : reverse, false);
5571 12138 : break;
5572 :
5573 9291 : case BITINT_TYPE:
5574 9291 : do_bitint:
5575 9291 : if (TREE_CODE (exp) != INTEGER_CST)
5576 0 : error ("initializer for %<_BitInt(%d)%> value is not an integer "
5577 0 : "constant", TYPE_PRECISION (TREE_TYPE (exp)));
5578 : else
5579 : {
5580 9291 : struct bitint_info info;
5581 9291 : tree type = TREE_TYPE (exp);
5582 9291 : bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info);
5583 9291 : gcc_assert (ok);
5584 9291 : scalar_int_mode limb_mode
5585 9291 : = as_a <scalar_int_mode> (info.abi_limb_mode);
5586 9291 : if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode))
5587 : {
5588 516 : cst = expand_expr (exp, NULL_RTX, VOIDmode, EXPAND_INITIALIZER);
5589 516 : if (reverse)
5590 0 : cst = flip_storage_order (TYPE_MODE (TREE_TYPE (exp)), cst);
5591 516 : if (!assemble_integer (cst, MIN (size, thissize), align, 0))
5592 0 : error ("initializer for integer/fixed-point value is too "
5593 : "complicated");
5594 516 : break;
5595 : }
5596 8775 : int prec = GET_MODE_PRECISION (limb_mode);
5597 8775 : int cnt = CEIL (TYPE_PRECISION (type), prec);
5598 8775 : tree limb_type = build_nonstandard_integer_type (prec, 1);
5599 8775 : int elt_size = GET_MODE_SIZE (limb_mode);
5600 8775 : unsigned int nalign = MIN (align, GET_MODE_ALIGNMENT (limb_mode));
5601 8775 : thissize = 0;
5602 8775 : if (prec == HOST_BITS_PER_WIDE_INT)
5603 107316 : for (int i = 0; i < cnt; i++)
5604 : {
5605 98541 : int idx = (info.big_endian ^ reverse) ? cnt - 1 - i : i;
5606 98541 : tree c;
5607 98541 : if (idx >= TREE_INT_CST_EXT_NUNITS (exp))
5608 37264 : c = build_int_cst (limb_type,
5609 72023 : tree_int_cst_sgn (exp) < 0 ? -1 : 0);
5610 : else
5611 61277 : c = build_int_cst (limb_type,
5612 61277 : TREE_INT_CST_ELT (exp, idx));
5613 98541 : output_constant (c, elt_size, nalign, reverse, false);
5614 98541 : thissize += elt_size;
5615 : }
5616 : else
5617 0 : for (int i = 0; i < cnt; i++)
5618 : {
5619 0 : int idx = (info.big_endian ^ reverse) ? cnt - 1 - i : i;
5620 0 : wide_int w = wi::rshift (wi::to_wide (exp), idx * prec,
5621 0 : TYPE_SIGN (TREE_TYPE (exp)));
5622 0 : tree c = wide_int_to_tree (limb_type,
5623 0 : wide_int::from (w, prec, UNSIGNED));
5624 0 : output_constant (c, elt_size, nalign, reverse, false);
5625 0 : thissize += elt_size;
5626 0 : }
5627 : }
5628 : break;
5629 :
5630 1932597 : case ARRAY_TYPE:
5631 1932597 : case VECTOR_TYPE:
5632 1932597 : switch (TREE_CODE (exp))
5633 : {
5634 576837 : case CONSTRUCTOR:
5635 576837 : return output_constructor (exp, size, align, reverse, NULL);
5636 1343463 : case STRING_CST:
5637 1343463 : thissize = (unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp);
5638 1343463 : if (merge_strings
5639 1343463 : && (thissize == 0
5640 413192 : || TREE_STRING_POINTER (exp) [thissize - 1] != '\0'))
5641 34515 : thissize++;
5642 1343463 : gcc_checking_assert (check_string_literal (exp, size));
5643 1343463 : assemble_string (TREE_STRING_POINTER (exp), thissize);
5644 1343463 : break;
5645 12297 : case VECTOR_CST:
5646 12297 : {
5647 12297 : scalar_mode inner = SCALAR_TYPE_MODE (TREE_TYPE (TREE_TYPE (exp)));
5648 12297 : unsigned int nalign = MIN (align, GET_MODE_ALIGNMENT (inner));
5649 12297 : int elt_size = GET_MODE_SIZE (inner);
5650 12297 : output_constant (VECTOR_CST_ELT (exp, 0), elt_size, align,
5651 : reverse, false);
5652 12297 : thissize = elt_size;
5653 : /* Static constants must have a fixed size. */
5654 12297 : unsigned int nunits = VECTOR_CST_NELTS (exp).to_constant ();
5655 69546 : for (unsigned int i = 1; i < nunits; i++)
5656 : {
5657 57249 : output_constant (VECTOR_CST_ELT (exp, i), elt_size, nalign,
5658 : reverse, false);
5659 57249 : thissize += elt_size;
5660 : }
5661 : break;
5662 : }
5663 0 : default:
5664 0 : gcc_unreachable ();
5665 : }
5666 : break;
5667 :
5668 3229191 : case RECORD_TYPE:
5669 3229191 : case UNION_TYPE:
5670 3229191 : gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
5671 3229191 : return output_constructor (exp, size, align, reverse, NULL);
5672 :
5673 : case ERROR_MARK:
5674 : return 0;
5675 :
5676 0 : default:
5677 0 : gcc_unreachable ();
5678 : }
5679 :
5680 14247225 : if (size > thissize)
5681 723460 : assemble_zeros (size - thissize);
5682 :
5683 : return size;
5684 : }
5685 :
5686 : /* Subroutine of output_constructor, used for computing the size of
5687 : arrays of unspecified length. VAL must be a CONSTRUCTOR of an array
5688 : type with an unspecified upper bound. */
5689 :
5690 : static unsigned HOST_WIDE_INT
5691 5563 : array_size_for_constructor (tree val)
5692 : {
5693 5563 : tree max_index;
5694 5563 : unsigned HOST_WIDE_INT cnt;
5695 5563 : tree index, value, tmp;
5696 5563 : offset_int i;
5697 :
5698 : /* This code used to attempt to handle string constants that are not
5699 : arrays of single-bytes, but nothing else does, so there's no point in
5700 : doing it here. */
5701 5563 : if (TREE_CODE (val) == STRING_CST)
5702 5388 : return TREE_STRING_LENGTH (val);
5703 :
5704 : max_index = NULL_TREE;
5705 491 : FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value)
5706 : {
5707 316 : if (TREE_CODE (index) == RANGE_EXPR)
5708 0 : index = TREE_OPERAND (index, 1);
5709 316 : if (value && TREE_CODE (value) == RAW_DATA_CST)
5710 8 : index = size_binop (PLUS_EXPR, index,
5711 : build_int_cst (TREE_TYPE (index),
5712 : RAW_DATA_LENGTH (value) - 1));
5713 316 : if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index))
5714 : max_index = index;
5715 : }
5716 :
5717 175 : if (max_index == NULL_TREE)
5718 : return 0;
5719 :
5720 : /* Compute the total number of array elements. */
5721 136 : tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val)));
5722 136 : i = wi::to_offset (max_index) - wi::to_offset (tmp) + 1;
5723 :
5724 : /* Multiply by the array element unit size to find number of bytes. */
5725 136 : i *= wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val))));
5726 :
5727 136 : gcc_assert (wi::fits_uhwi_p (i));
5728 136 : return i.to_uhwi ();
5729 : }
5730 :
5731 : /* Other datastructures + helpers for output_constructor. */
5732 :
5733 : /* output_constructor local state to support interaction with helpers. */
5734 :
5735 : struct oc_local_state {
5736 :
5737 : /* Received arguments. */
5738 : tree exp; /* Constructor expression. */
5739 : tree type; /* Type of constructor expression. */
5740 : unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */
5741 : unsigned int align; /* Known initial alignment. */
5742 : tree min_index; /* Lower bound if specified for an array. */
5743 :
5744 : /* Output processing state. */
5745 : HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */
5746 : int byte; /* Part of a bitfield byte yet to be output. */
5747 : int last_relative_index; /* Implicit or explicit index of the last
5748 : array element output within a bitfield. */
5749 : bool byte_buffer_in_use; /* Whether BYTE is in use. */
5750 : bool reverse; /* Whether reverse storage order is in use. */
5751 :
5752 : /* Current element. */
5753 : tree field; /* Current field decl in a record. */
5754 : tree val; /* Current element value. */
5755 : tree index; /* Current element index. */
5756 :
5757 : };
5758 :
5759 : /* Helper for output_constructor. From the current LOCAL state, output a
5760 : RANGE_EXPR element. */
5761 :
5762 : static void
5763 971 : output_constructor_array_range (oc_local_state *local)
5764 : {
5765 : /* Perform the index calculation in modulo arithmetic but
5766 : sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5767 : but we are using an unsigned sizetype. */
5768 971 : unsigned prec = TYPE_PRECISION (sizetype);
5769 971 : offset_int idx = wi::sext (wi::to_offset (TREE_OPERAND (local->index, 0))
5770 1942 : - wi::to_offset (local->min_index), prec);
5771 971 : tree valtype = TREE_TYPE (local->val);
5772 971 : HOST_WIDE_INT fieldpos
5773 971 : = (idx * wi::to_offset (TYPE_SIZE_UNIT (valtype))).to_short_addr ();
5774 :
5775 : /* Advance to offset of this element. */
5776 971 : if (fieldpos > local->total_bytes)
5777 : {
5778 8 : assemble_zeros (fieldpos - local->total_bytes);
5779 8 : local->total_bytes = fieldpos;
5780 : }
5781 : else
5782 : /* Must not go backwards. */
5783 963 : gcc_assert (fieldpos == local->total_bytes);
5784 :
5785 971 : unsigned HOST_WIDE_INT fieldsize
5786 971 : = int_size_in_bytes (TREE_TYPE (local->type));
5787 :
5788 971 : HOST_WIDE_INT lo_index
5789 971 : = tree_to_shwi (TREE_OPERAND (local->index, 0));
5790 971 : HOST_WIDE_INT hi_index
5791 971 : = tree_to_shwi (TREE_OPERAND (local->index, 1));
5792 971 : HOST_WIDE_INT index;
5793 :
5794 971 : unsigned int align2
5795 971 : = min_align (local->align, fieldsize * BITS_PER_UNIT);
5796 :
5797 275891 : for (index = lo_index; index <= hi_index; index++)
5798 : {
5799 : /* Output the element's initial value. */
5800 274920 : if (local->val == NULL_TREE)
5801 0 : assemble_zeros (fieldsize);
5802 : else
5803 274920 : fieldsize = output_constant (local->val, fieldsize, align2,
5804 : local->reverse, false);
5805 :
5806 : /* Count its size. */
5807 274920 : local->total_bytes += fieldsize;
5808 : }
5809 971 : }
5810 :
5811 : /* Helper for output_constructor. From the current LOCAL state, output a
5812 : field element that is not true bitfield or part of an outer one. */
5813 :
5814 : static void
5815 14468572 : output_constructor_regular_field (oc_local_state *local)
5816 : {
5817 : /* Field size and position. Since this structure is static, we know the
5818 : positions are constant. */
5819 14468572 : unsigned HOST_WIDE_INT fieldsize;
5820 14468572 : HOST_WIDE_INT fieldpos;
5821 :
5822 14468572 : unsigned int align2;
5823 :
5824 : /* Output any buffered-up bit-fields preceding this element. */
5825 14468572 : if (local->byte_buffer_in_use)
5826 : {
5827 500 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5828 500 : local->total_bytes++;
5829 500 : local->byte_buffer_in_use = false;
5830 : }
5831 :
5832 14468572 : if (local->index != NULL_TREE)
5833 : {
5834 : /* Perform the index calculation in modulo arithmetic but
5835 : sign-extend the result because Ada has negative DECL_FIELD_OFFSETs
5836 : but we are using an unsigned sizetype. */
5837 4031124 : unsigned prec = TYPE_PRECISION (sizetype);
5838 4031124 : offset_int idx = wi::sext (wi::to_offset (local->index)
5839 8062248 : - wi::to_offset (local->min_index), prec);
5840 4031124 : fieldpos = (idx * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local->val))))
5841 4031124 : .to_short_addr ();
5842 : }
5843 10437448 : else if (local->field != NULL_TREE)
5844 9575816 : fieldpos = int_byte_position (local->field);
5845 : else
5846 : fieldpos = 0;
5847 :
5848 : /* Advance to offset of this element.
5849 : Note no alignment needed in an array, since that is guaranteed
5850 : if each element has the proper size. */
5851 14468572 : if (local->field != NULL_TREE || local->index != NULL_TREE)
5852 : {
5853 13606940 : if (fieldpos > local->total_bytes)
5854 : {
5855 180127 : assemble_zeros (fieldpos - local->total_bytes);
5856 180127 : local->total_bytes = fieldpos;
5857 : }
5858 : else
5859 : /* Must not go backwards. */
5860 13426813 : gcc_assert (fieldpos == local->total_bytes);
5861 : }
5862 :
5863 : /* Find the alignment of this element. */
5864 14468572 : align2 = min_align (local->align, BITS_PER_UNIT * fieldpos);
5865 :
5866 : /* Determine size this element should occupy. */
5867 14468572 : if (local->field)
5868 : {
5869 9575816 : fieldsize = 0;
5870 :
5871 : /* If this is an array with an unspecified upper bound,
5872 : the initializer determines the size. */
5873 : /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL,
5874 : but we cannot do this until the deprecated support for
5875 : initializing zero-length array members is removed. */
5876 9575816 : if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE
5877 9575816 : && (!TYPE_DOMAIN (TREE_TYPE (local->field))
5878 183050 : || !TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field)))))
5879 : {
5880 5563 : unsigned HOST_WIDE_INT fldsize
5881 5563 : = array_size_for_constructor (local->val);
5882 5563 : fieldsize = int_size_in_bytes (TREE_TYPE (local->val));
5883 : /* In most cases fieldsize == fldsize as the size of the initializer
5884 : determines how many elements the flexible array member has. For
5885 : C++ fldsize can be smaller though, if the last or several last or
5886 : all initializers of the flexible array member have side-effects
5887 : and the FE splits them into dynamic initialization. */
5888 5563 : gcc_checking_assert (fieldsize >= fldsize);
5889 : /* Given a non-empty initialization, this field had better
5890 : be last except in unions. Given a flexible array member, the next
5891 : field on the chain is a TYPE_DECL of the enclosing struct. */
5892 5563 : const_tree next = DECL_CHAIN (local->field);
5893 5563 : gcc_assert (!fieldsize
5894 : || !next
5895 : || TREE_CODE (next) != FIELD_DECL
5896 : || TREE_CODE (local->type) == UNION_TYPE);
5897 : }
5898 : else
5899 9570253 : fieldsize = tree_to_uhwi (DECL_SIZE_UNIT (local->field));
5900 : }
5901 : else
5902 4892756 : fieldsize = int_size_in_bytes (TREE_TYPE (local->type));
5903 :
5904 : /* Output the element's initial value. */
5905 14468572 : if (local->val == NULL_TREE)
5906 0 : assemble_zeros (fieldsize);
5907 14468572 : else if (local->val && TREE_CODE (local->val) == RAW_DATA_CST)
5908 : {
5909 445 : fieldsize *= RAW_DATA_LENGTH (local->val);
5910 445 : assemble_string (RAW_DATA_POINTER (local->val),
5911 445 : RAW_DATA_LENGTH (local->val));
5912 : }
5913 : else
5914 14468127 : fieldsize = output_constant (local->val, fieldsize, align2,
5915 : local->reverse, false);
5916 :
5917 : /* Count its size. */
5918 14468572 : local->total_bytes += fieldsize;
5919 14468572 : }
5920 :
5921 : /* Helper for output_constructor. From the LOCAL state, output an element
5922 : that is a true bitfield or part of an outer one. BIT_OFFSET is the offset
5923 : from the start of a possibly ongoing outer byte buffer. */
5924 :
5925 : static void
5926 9774 : output_constructor_bitfield (oc_local_state *local, unsigned int bit_offset)
5927 : {
5928 : /* Bit size of this element. */
5929 9774 : HOST_WIDE_INT ebitsize
5930 9774 : = (local->field
5931 9774 : ? tree_to_uhwi (DECL_SIZE (local->field))
5932 9774 : : tree_to_uhwi (TYPE_SIZE (TREE_TYPE (local->type))));
5933 :
5934 : /* Relative index of this element if this is an array component. */
5935 9774 : HOST_WIDE_INT relative_index
5936 : = (local->field
5937 9774 : ? 0
5938 0 : : (local->index
5939 0 : ? tree_to_uhwi (local->index) - tree_to_uhwi (local->min_index)
5940 0 : : local->last_relative_index + 1));
5941 :
5942 : /* Bit position of this element from the start of the containing
5943 : constructor. */
5944 9774 : HOST_WIDE_INT constructor_relative_ebitpos
5945 : = (local->field
5946 9774 : ? int_bit_position (local->field)
5947 0 : : ebitsize * relative_index);
5948 :
5949 : /* Bit position of this element from the start of a possibly ongoing
5950 : outer byte buffer. */
5951 9774 : HOST_WIDE_INT byte_relative_ebitpos
5952 9774 : = bit_offset + constructor_relative_ebitpos;
5953 :
5954 : /* From the start of a possibly ongoing outer byte buffer, offsets to
5955 : the first bit of this element and to the first bit past the end of
5956 : this element. */
5957 9774 : HOST_WIDE_INT next_offset = byte_relative_ebitpos;
5958 9774 : HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize;
5959 :
5960 9774 : local->last_relative_index = relative_index;
5961 :
5962 9774 : if (local->val == NULL_TREE)
5963 0 : local->val = integer_zero_node;
5964 :
5965 9774 : while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR
5966 9774 : || TREE_CODE (local->val) == NON_LVALUE_EXPR)
5967 0 : local->val = TREE_OPERAND (local->val, 0);
5968 :
5969 9774 : if (TREE_CODE (local->val) != INTEGER_CST
5970 0 : && TREE_CODE (local->val) != CONSTRUCTOR)
5971 : {
5972 0 : error ("invalid initial value for member %qE", DECL_NAME (local->field));
5973 0 : return;
5974 : }
5975 :
5976 : /* If this field does not start in this (or next) byte, skip some bytes. */
5977 9774 : if (next_offset / BITS_PER_UNIT != local->total_bytes)
5978 : {
5979 : /* Output remnant of any bit field in previous bytes. */
5980 1300 : if (local->byte_buffer_in_use)
5981 : {
5982 1271 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
5983 1271 : local->total_bytes++;
5984 1271 : local->byte_buffer_in_use = false;
5985 : }
5986 :
5987 : /* If still not at proper byte, advance to there. */
5988 1300 : if (next_offset / BITS_PER_UNIT != local->total_bytes)
5989 : {
5990 120 : gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes);
5991 120 : assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes);
5992 120 : local->total_bytes = next_offset / BITS_PER_UNIT;
5993 : }
5994 : }
5995 :
5996 : /* Set up the buffer if necessary. */
5997 9774 : if (!local->byte_buffer_in_use)
5998 : {
5999 4168 : local->byte = 0;
6000 4168 : if (ebitsize > 0)
6001 4168 : local->byte_buffer_in_use = true;
6002 : }
6003 :
6004 : /* If this is nested constructor, recurse passing the bit offset and the
6005 : pending data, then retrieve the new pending data afterwards. */
6006 9774 : if (TREE_CODE (local->val) == CONSTRUCTOR)
6007 : {
6008 0 : oc_outer_state temp_state;
6009 0 : temp_state.bit_offset = next_offset % BITS_PER_UNIT;
6010 0 : temp_state.byte = local->byte;
6011 0 : local->total_bytes
6012 0 : += output_constructor (local->val, 0, 0, local->reverse, &temp_state);
6013 0 : local->byte = temp_state.byte;
6014 0 : return;
6015 : }
6016 :
6017 : /* Otherwise, we must split the element into pieces that fall within
6018 : separate bytes, and combine each byte with previous or following
6019 : bit-fields. */
6020 40761 : while (next_offset < end_offset)
6021 : {
6022 30987 : int this_time;
6023 30987 : int shift;
6024 30987 : unsigned HOST_WIDE_INT value;
6025 30987 : HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
6026 30987 : HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
6027 :
6028 : /* Advance from byte to byte within this element when necessary. */
6029 51656 : while (next_byte != local->total_bytes)
6030 : {
6031 20669 : assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1);
6032 20669 : local->total_bytes++;
6033 20669 : local->byte = 0;
6034 : }
6035 :
6036 : /* Number of bits we can process at once (all part of the same byte). */
6037 30987 : this_time = MIN (end_offset - next_offset, BITS_PER_UNIT - next_bit);
6038 30987 : if (local->reverse ? !BYTES_BIG_ENDIAN : BYTES_BIG_ENDIAN)
6039 : {
6040 : /* For big-endian data, take the most significant bits (of the
6041 : bits that are significant) first and put them into bytes from
6042 : the most significant end. */
6043 778 : shift = end_offset - next_offset - this_time;
6044 :
6045 : /* Don't try to take a bunch of bits that cross
6046 : the word boundary in the INTEGER_CST. We can
6047 : only select bits from one element. */
6048 778 : if ((shift / HOST_BITS_PER_WIDE_INT)
6049 778 : != ((shift + this_time - 1) / HOST_BITS_PER_WIDE_INT))
6050 : {
6051 0 : const int end = shift + this_time - 1;
6052 0 : shift = end & -HOST_BITS_PER_WIDE_INT;
6053 0 : this_time = end - shift + 1;
6054 : }
6055 :
6056 : /* Now get the bits we want to insert. */
6057 778 : value = wi::extract_uhwi (wi::to_widest (local->val),
6058 : shift, this_time);
6059 :
6060 : /* Get the result. This works only when:
6061 : 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
6062 778 : local->byte |= value << (BITS_PER_UNIT - this_time - next_bit);
6063 : }
6064 : else
6065 : {
6066 : /* On little-endian machines, take the least significant bits of
6067 : the value first and pack them starting at the least significant
6068 : bits of the bytes. */
6069 30209 : shift = next_offset - byte_relative_ebitpos;
6070 :
6071 : /* Don't try to take a bunch of bits that cross
6072 : the word boundary in the INTEGER_CST. We can
6073 : only select bits from one element. */
6074 30209 : if ((shift / HOST_BITS_PER_WIDE_INT)
6075 30209 : != ((shift + this_time - 1) / HOST_BITS_PER_WIDE_INT))
6076 544 : this_time
6077 544 : = HOST_BITS_PER_WIDE_INT - (shift & (HOST_BITS_PER_WIDE_INT - 1));
6078 :
6079 : /* Now get the bits we want to insert. */
6080 30209 : value = wi::extract_uhwi (wi::to_widest (local->val),
6081 : shift, this_time);
6082 :
6083 : /* Get the result. This works only when:
6084 : 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
6085 30209 : local->byte |= value << next_bit;
6086 : }
6087 :
6088 30987 : next_offset += this_time;
6089 30987 : local->byte_buffer_in_use = true;
6090 : }
6091 : }
6092 :
6093 : /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants).
6094 : Generate at least SIZE bytes, padding if necessary. OUTER designates the
6095 : caller output state of relevance in recursive invocations. */
6096 :
6097 : static unsigned HOST_WIDE_INT
6098 3806028 : output_constructor (tree exp, unsigned HOST_WIDE_INT size, unsigned int align,
6099 : bool reverse, oc_outer_state *outer)
6100 : {
6101 3806028 : unsigned HOST_WIDE_INT cnt;
6102 3806028 : constructor_elt *ce;
6103 3806028 : oc_local_state local;
6104 :
6105 : /* Setup our local state to communicate with helpers. */
6106 3806028 : local.exp = exp;
6107 3806028 : local.type = TREE_TYPE (exp);
6108 3806028 : local.size = size;
6109 3806028 : local.align = align;
6110 3806028 : if (TREE_CODE (local.type) == ARRAY_TYPE && TYPE_DOMAIN (local.type))
6111 576837 : local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type));
6112 : else
6113 3229191 : local.min_index = integer_zero_node;
6114 :
6115 3806028 : local.total_bytes = 0;
6116 3806028 : local.byte_buffer_in_use = outer != NULL;
6117 3806028 : local.byte = outer ? outer->byte : 0;
6118 3806028 : local.last_relative_index = -1;
6119 : /* The storage order is specified for every aggregate type. */
6120 3806028 : if (AGGREGATE_TYPE_P (local.type))
6121 3806028 : local.reverse = TYPE_REVERSE_STORAGE_ORDER (local.type);
6122 : else
6123 : local.reverse = reverse;
6124 :
6125 3806028 : gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT);
6126 :
6127 : /* As CE goes through the elements of the constant, FIELD goes through the
6128 : structure fields if the constant is a structure. If the constant is a
6129 : union, we override this by getting the field from the TREE_LIST element.
6130 : But the constant could also be an array. Then FIELD is zero.
6131 :
6132 : There is always a maximum of one element in the chain LINK for unions
6133 : (even if the initializer in a source program incorrectly contains
6134 : more one). */
6135 :
6136 3806028 : if (TREE_CODE (local.type) == RECORD_TYPE)
6137 3208546 : local.field = TYPE_FIELDS (local.type);
6138 : else
6139 : local.field = NULL_TREE;
6140 :
6141 3806028 : for (cnt = 0;
6142 18285345 : vec_safe_iterate (CONSTRUCTOR_ELTS (exp), cnt, &ce);
6143 14479317 : cnt++, local.field = local.field ? DECL_CHAIN (local.field) : 0)
6144 : {
6145 14479317 : local.val = ce->value;
6146 14479317 : local.index = NULL_TREE;
6147 :
6148 : /* The element in a union constructor specifies the proper field
6149 : or index. */
6150 14479317 : if (RECORD_OR_UNION_TYPE_P (local.type) && ce->index != NULL_TREE)
6151 9382613 : local.field = ce->index;
6152 :
6153 5096704 : else if (TREE_CODE (local.type) == ARRAY_TYPE)
6154 4893727 : local.index = ce->index;
6155 :
6156 14479317 : if (local.field && flag_verbose_asm)
6157 0 : fprintf (asm_out_file, "%s %s:\n",
6158 : ASM_COMMENT_START,
6159 0 : DECL_NAME (local.field)
6160 0 : ? IDENTIFIER_POINTER (DECL_NAME (local.field))
6161 : : "<anonymous>");
6162 :
6163 : /* Eliminate the marker that makes a cast not be an lvalue. */
6164 14479317 : if (local.val != NULL_TREE)
6165 14479317 : STRIP_NOPS (local.val);
6166 :
6167 : /* Output the current element, using the appropriate helper ... */
6168 :
6169 : /* For an array slice not part of an outer bitfield. */
6170 14479317 : if (!outer
6171 14479317 : && local.index != NULL_TREE
6172 4032095 : && TREE_CODE (local.index) == RANGE_EXPR)
6173 971 : output_constructor_array_range (&local);
6174 :
6175 : /* For a field that is neither a true bitfield nor part of an outer one,
6176 : known to be at least byte aligned and multiple-of-bytes long. */
6177 14478346 : else if (!outer
6178 14478346 : && (local.field == NULL_TREE
6179 9585590 : || !CONSTRUCTOR_BITFIELD_P (local.field)))
6180 14468572 : output_constructor_regular_field (&local);
6181 :
6182 : /* For a true bitfield or part of an outer one. Only INTEGER_CSTs are
6183 : supported for scalar fields, so we may need to convert first. */
6184 : else
6185 : {
6186 9774 : if (TREE_CODE (local.val) == REAL_CST)
6187 0 : local.val
6188 0 : = fold_unary (VIEW_CONVERT_EXPR,
6189 : build_nonstandard_integer_type
6190 : (TYPE_PRECISION (TREE_TYPE (local.val)), 0),
6191 : local.val);
6192 9774 : output_constructor_bitfield (&local, outer ? outer->bit_offset : 0);
6193 : }
6194 : }
6195 :
6196 : /* If we are not at toplevel, save the pending data for our caller.
6197 : Otherwise output the pending data and padding zeros as needed. */
6198 3806028 : if (outer)
6199 0 : outer->byte = local.byte;
6200 : else
6201 : {
6202 3806028 : if (local.byte_buffer_in_use)
6203 : {
6204 2397 : assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1);
6205 2397 : local.total_bytes++;
6206 : }
6207 :
6208 3806028 : if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size)
6209 : {
6210 52539 : assemble_zeros (local.size - local.total_bytes);
6211 52539 : local.total_bytes = local.size;
6212 : }
6213 : }
6214 :
6215 3806028 : return local.total_bytes;
6216 : }
6217 :
6218 : /* Mark DECL as weak. */
6219 :
6220 : static void
6221 129966 : mark_weak (tree decl)
6222 : {
6223 129966 : if (DECL_WEAK (decl))
6224 : return;
6225 :
6226 129952 : struct symtab_node *n = symtab_node::get (decl);
6227 129952 : if (n && n->refuse_visibility_changes)
6228 3 : error ("%qD declared weak after being used", decl);
6229 129952 : DECL_WEAK (decl) = 1;
6230 :
6231 129952 : if (DECL_RTL_SET_P (decl)
6232 0 : && MEM_P (DECL_RTL (decl))
6233 0 : && XEXP (DECL_RTL (decl), 0)
6234 129952 : && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
6235 0 : SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1;
6236 : }
6237 :
6238 : /* Merge weak status between NEWDECL and OLDDECL. */
6239 :
6240 : void
6241 21417565 : merge_weak (tree newdecl, tree olddecl)
6242 : {
6243 21417565 : if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl))
6244 : {
6245 21399529 : if (DECL_WEAK (newdecl) && TARGET_SUPPORTS_WEAK)
6246 : {
6247 : tree *pwd;
6248 : /* We put the NEWDECL on the weak_decls list at some point
6249 : and OLDDECL as well. Keep just OLDDECL on the list. */
6250 158 : for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd))
6251 0 : if (TREE_VALUE (*pwd) == newdecl)
6252 : {
6253 0 : *pwd = TREE_CHAIN (*pwd);
6254 0 : break;
6255 : }
6256 : }
6257 : return;
6258 : }
6259 :
6260 18036 : if (DECL_WEAK (newdecl))
6261 : {
6262 295 : tree wd;
6263 :
6264 : /* NEWDECL is weak, but OLDDECL is not. */
6265 :
6266 : /* If we already output the OLDDECL, we're in trouble; we can't
6267 : go back and make it weak. This should never happen in
6268 : unit-at-a-time compilation. */
6269 295 : gcc_assert (!TREE_ASM_WRITTEN (olddecl));
6270 :
6271 : /* If we've already generated rtl referencing OLDDECL, we may
6272 : have done so in a way that will not function properly with
6273 : a weak symbol. Again in unit-at-a-time this should be
6274 : impossible. */
6275 295 : gcc_assert (!TREE_USED (olddecl)
6276 : || !TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl)));
6277 :
6278 : /* PR 49899: You cannot convert a static function into a weak, public function. */
6279 295 : if (! TREE_PUBLIC (olddecl) && TREE_PUBLIC (newdecl))
6280 1 : error ("weak declaration of %q+D being applied to a already "
6281 : "existing, static definition", newdecl);
6282 :
6283 295 : if (TARGET_SUPPORTS_WEAK)
6284 : {
6285 : /* We put the NEWDECL on the weak_decls list at some point.
6286 : Replace it with the OLDDECL. */
6287 295 : for (wd = weak_decls; wd; wd = TREE_CHAIN (wd))
6288 0 : if (TREE_VALUE (wd) == newdecl)
6289 : {
6290 0 : TREE_VALUE (wd) = olddecl;
6291 0 : break;
6292 : }
6293 : /* We may not find the entry on the list. If NEWDECL is a
6294 : weak alias, then we will have already called
6295 : globalize_decl to remove the entry; in that case, we do
6296 : not need to do anything. */
6297 : }
6298 :
6299 : /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */
6300 295 : mark_weak (olddecl);
6301 : }
6302 : else
6303 : /* OLDDECL was weak, but NEWDECL was not explicitly marked as
6304 : weak. Just update NEWDECL to indicate that it's weak too. */
6305 17741 : mark_weak (newdecl);
6306 : }
6307 :
6308 : /* Declare DECL to be a weak symbol. */
6309 :
6310 : void
6311 111935 : declare_weak (tree decl)
6312 : {
6313 : /* With -fsyntax-only, TREE_ASM_WRITTEN might be set on certain function
6314 : decls earlier than normally, but as with -fsyntax-only nothing is really
6315 : emitted, there is no harm in marking it weak later. */
6316 111935 : gcc_assert (TREE_CODE (decl) != FUNCTION_DECL
6317 : || !TREE_ASM_WRITTEN (decl)
6318 : || flag_syntax_only);
6319 111935 : if (! TREE_PUBLIC (decl))
6320 : {
6321 5 : error ("weak declaration of %q+D must be public", decl);
6322 5 : return;
6323 : }
6324 111930 : else if (!TARGET_SUPPORTS_WEAK)
6325 : warning (0, "weak declaration of %q+D not supported", decl);
6326 :
6327 111930 : mark_weak (decl);
6328 111930 : if (!lookup_attribute ("weak", DECL_ATTRIBUTES (decl)))
6329 111916 : DECL_ATTRIBUTES (decl)
6330 223832 : = tree_cons (get_identifier ("weak"), NULL, DECL_ATTRIBUTES (decl));
6331 : }
6332 :
6333 : static void
6334 1004 : weak_finish_1 (tree decl)
6335 : {
6336 : #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL)
6337 1004 : const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
6338 : #endif
6339 :
6340 1004 : if (! TREE_USED (decl))
6341 : return;
6342 :
6343 : #ifdef ASM_WEAKEN_DECL
6344 : ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL);
6345 : #else
6346 : #ifdef ASM_WEAKEN_LABEL
6347 1004 : ASM_WEAKEN_LABEL (asm_out_file, name);
6348 : #else
6349 : #ifdef ASM_OUTPUT_WEAK_ALIAS
6350 : {
6351 : static bool warn_once = 0;
6352 : if (! warn_once)
6353 : {
6354 : warning (0, "only weak aliases are supported in this configuration");
6355 : warn_once = 1;
6356 : }
6357 : return;
6358 : }
6359 : #endif
6360 : #endif
6361 : #endif
6362 : }
6363 :
6364 : /* Fiven an assembly name, find the decl it is associated with. */
6365 : static tree
6366 0 : find_decl (tree target)
6367 : {
6368 0 : symtab_node *node = symtab_node::get_for_asmname (target);
6369 0 : if (node)
6370 0 : return node->decl;
6371 : return NULL_TREE;
6372 : }
6373 :
6374 : /* This TREE_LIST contains weakref targets. */
6375 :
6376 : static GTY(()) tree weakref_targets;
6377 :
6378 : /* Emit any pending weak declarations. */
6379 :
6380 : void
6381 243525 : weak_finish (void)
6382 : {
6383 243525 : tree t;
6384 :
6385 243625 : for (t = weakref_targets; t; t = TREE_CHAIN (t))
6386 : {
6387 100 : tree alias_decl = TREE_PURPOSE (t);
6388 100 : tree target = ultimate_transparent_alias_target (&TREE_VALUE (t));
6389 :
6390 100 : if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl))
6391 200 : || TREE_SYMBOL_REFERENCED (target))
6392 : /* Remove alias_decl from the weak list, but leave entries for
6393 : the target alone. */
6394 : target = NULL_TREE;
6395 : #ifndef ASM_OUTPUT_WEAKREF
6396 : else if (! TREE_SYMBOL_REFERENCED (target))
6397 : {
6398 : /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not
6399 : defined, otherwise we and weak_finish_1 would use
6400 : different macros. */
6401 : # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL
6402 : ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target));
6403 : # else
6404 : tree decl = find_decl (target);
6405 :
6406 : if (! decl)
6407 : {
6408 : decl = build_decl (DECL_SOURCE_LOCATION (alias_decl),
6409 : TREE_CODE (alias_decl), target,
6410 : TREE_TYPE (alias_decl));
6411 :
6412 : DECL_EXTERNAL (decl) = 1;
6413 : TREE_PUBLIC (decl) = 1;
6414 : DECL_ARTIFICIAL (decl) = 1;
6415 : TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl);
6416 : TREE_USED (decl) = 1;
6417 : }
6418 :
6419 : weak_finish_1 (decl);
6420 : # endif
6421 : }
6422 : #endif
6423 :
6424 100 : {
6425 100 : tree *p;
6426 100 : tree t2;
6427 :
6428 : /* Remove the alias and the target from the pending weak list
6429 : so that we do not emit any .weak directives for the former,
6430 : nor multiple .weak directives for the latter. */
6431 168 : for (p = &weak_decls; (t2 = *p) ; )
6432 : {
6433 68 : if (TREE_VALUE (t2) == alias_decl
6434 68 : || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2)))
6435 0 : *p = TREE_CHAIN (t2);
6436 : else
6437 68 : p = &TREE_CHAIN (t2);
6438 : }
6439 :
6440 : /* Remove other weakrefs to the same target, to speed things up. */
6441 212 : for (p = &TREE_CHAIN (t); (t2 = *p) ; )
6442 : {
6443 112 : if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2)))
6444 0 : *p = TREE_CHAIN (t2);
6445 : else
6446 112 : p = &TREE_CHAIN (t2);
6447 : }
6448 : }
6449 : }
6450 :
6451 244529 : for (t = weak_decls; t; t = TREE_CHAIN (t))
6452 : {
6453 1004 : tree decl = TREE_VALUE (t);
6454 :
6455 1004 : weak_finish_1 (decl);
6456 : }
6457 243525 : }
6458 :
6459 : /* Emit the assembly bits to indicate that DECL is globally visible. */
6460 :
6461 : static void
6462 2721165 : globalize_decl (tree decl)
6463 : {
6464 :
6465 : #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL)
6466 2721165 : if (DECL_WEAK (decl))
6467 : {
6468 548789 : const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
6469 548789 : tree *p, t;
6470 :
6471 : #ifdef ASM_WEAKEN_DECL
6472 : ASM_WEAKEN_DECL (asm_out_file, decl, name, 0);
6473 : #else
6474 548789 : ASM_WEAKEN_LABEL (asm_out_file, name);
6475 : #endif
6476 :
6477 : /* Remove this function from the pending weak list so that
6478 : we do not emit multiple .weak directives for it. */
6479 1102560 : for (p = &weak_decls; (t = *p) ; )
6480 : {
6481 4982 : if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
6482 0 : *p = TREE_CHAIN (t);
6483 : else
6484 4982 : p = &TREE_CHAIN (t);
6485 : }
6486 :
6487 : /* Remove weakrefs to the same target from the pending weakref
6488 : list, for the same reason. */
6489 548789 : for (p = &weakref_targets; (t = *p) ; )
6490 : {
6491 0 : if (DECL_ASSEMBLER_NAME (decl)
6492 0 : == ultimate_transparent_alias_target (&TREE_VALUE (t)))
6493 0 : *p = TREE_CHAIN (t);
6494 : else
6495 0 : p = &TREE_CHAIN (t);
6496 : }
6497 :
6498 : return;
6499 : }
6500 : #endif
6501 :
6502 2172376 : targetm.asm_out.globalize_decl_name (asm_out_file, decl);
6503 : }
6504 :
6505 : vec<alias_pair, va_gc> *alias_pairs;
6506 :
6507 : /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF
6508 : or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose
6509 : tree node is DECL to have the value of the tree node TARGET. */
6510 :
6511 : void
6512 68616 : do_assemble_alias (tree decl, tree target)
6513 : {
6514 68616 : tree id;
6515 :
6516 : /* Emulated TLS had better not get this var. */
6517 68616 : gcc_assert (!(!targetm.have_tls
6518 : && VAR_P (decl)
6519 : && DECL_THREAD_LOCAL_P (decl)));
6520 :
6521 68616 : if (TREE_ASM_WRITTEN (decl))
6522 127 : return;
6523 :
6524 68616 : id = DECL_ASSEMBLER_NAME (decl);
6525 68616 : ultimate_transparent_alias_target (&id);
6526 68616 : ultimate_transparent_alias_target (&target);
6527 :
6528 : /* We must force creation of DECL_RTL for debug info generation, even though
6529 : we don't use it here. */
6530 68616 : make_decl_rtl (decl);
6531 :
6532 68616 : TREE_ASM_WRITTEN (decl) = 1;
6533 68616 : TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1;
6534 68616 : TREE_ASM_WRITTEN (id) = 1;
6535 :
6536 68616 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
6537 : {
6538 127 : if (!TREE_SYMBOL_REFERENCED (target))
6539 100 : weakref_targets = tree_cons (decl, target, weakref_targets);
6540 :
6541 : #ifdef ASM_OUTPUT_WEAKREF
6542 127 : ASM_OUTPUT_WEAKREF (asm_out_file, decl,
6543 : IDENTIFIER_POINTER (id),
6544 : IDENTIFIER_POINTER (target));
6545 : #else
6546 : if (!TARGET_SUPPORTS_WEAK)
6547 : {
6548 : error_at (DECL_SOURCE_LOCATION (decl),
6549 : "%qs is not supported in this configuration", "weakref ");
6550 : return;
6551 : }
6552 : #endif
6553 127 : return;
6554 : }
6555 :
6556 : #ifdef ASM_OUTPUT_DEF
6557 68489 : tree orig_decl = decl;
6558 :
6559 : /* Make name accessible from other files, if appropriate. */
6560 :
6561 68489 : if (TREE_PUBLIC (decl) || TREE_PUBLIC (orig_decl))
6562 : {
6563 47778 : globalize_decl (decl);
6564 47778 : maybe_assemble_visibility (decl);
6565 : }
6566 68489 : if (TREE_CODE (decl) == FUNCTION_DECL
6567 68489 : && cgraph_node::get (decl)->ifunc_resolver)
6568 : {
6569 : #if defined (ASM_OUTPUT_TYPE_DIRECTIVE)
6570 302 : if (targetm.has_ifunc_p ())
6571 302 : ASM_OUTPUT_TYPE_DIRECTIVE
6572 : (asm_out_file, IDENTIFIER_POINTER (id),
6573 : IFUNC_ASM_TYPE);
6574 : else
6575 : #endif
6576 0 : error_at (DECL_SOURCE_LOCATION (decl),
6577 : "%qs is not supported on this target", "ifunc");
6578 : }
6579 :
6580 : # ifdef ASM_OUTPUT_DEF_FROM_DECLS
6581 : ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
6582 : # else
6583 68489 : ASM_OUTPUT_DEF (asm_out_file,
6584 : IDENTIFIER_POINTER (id),
6585 : IDENTIFIER_POINTER (target));
6586 : # endif
6587 : /* If symbol aliases aren't actually supported... */
6588 68489 : if (!TARGET_SUPPORTS_ALIASES
6589 : # ifdef ACCEL_COMPILER
6590 : /* ..., and unless special-cased... */
6591 : && !lookup_attribute ("symbol alias handled", DECL_ATTRIBUTES (decl))
6592 : # endif
6593 : )
6594 : /* ..., 'ASM_OUTPUT_DEF{,_FROM_DECLS}' better have raised an error. */
6595 : gcc_checking_assert (seen_error ());
6596 : #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL)
6597 : {
6598 : const char *name;
6599 : tree *p, t;
6600 :
6601 : name = IDENTIFIER_POINTER (id);
6602 : # ifdef ASM_WEAKEN_DECL
6603 : ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target));
6604 : # else
6605 : ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
6606 : # endif
6607 : /* Remove this function from the pending weak list so that
6608 : we do not emit multiple .weak directives for it. */
6609 : for (p = &weak_decls; (t = *p) ; )
6610 : if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))
6611 : || id == DECL_ASSEMBLER_NAME (TREE_VALUE (t)))
6612 : *p = TREE_CHAIN (t);
6613 : else
6614 : p = &TREE_CHAIN (t);
6615 :
6616 : /* Remove weakrefs to the same target from the pending weakref
6617 : list, for the same reason. */
6618 : for (p = &weakref_targets; (t = *p) ; )
6619 : {
6620 : if (id == ultimate_transparent_alias_target (&TREE_VALUE (t)))
6621 : *p = TREE_CHAIN (t);
6622 : else
6623 : p = &TREE_CHAIN (t);
6624 : }
6625 : }
6626 : #endif
6627 : }
6628 :
6629 : /* Output .symver directive. */
6630 :
6631 : void
6632 2 : do_assemble_symver (tree decl, tree target)
6633 : {
6634 2 : tree id = DECL_ASSEMBLER_NAME (decl);
6635 2 : ultimate_transparent_alias_target (&id);
6636 2 : ultimate_transparent_alias_target (&target);
6637 : #ifdef ASM_OUTPUT_SYMVER_DIRECTIVE
6638 2 : ASM_OUTPUT_SYMVER_DIRECTIVE (asm_out_file,
6639 : IDENTIFIER_POINTER (target),
6640 : IDENTIFIER_POINTER (id));
6641 : #else
6642 : error ("symver is only supported on ELF platforms");
6643 : #endif
6644 2 : }
6645 :
6646 : /* Emit an assembler directive to make the symbol for DECL an alias to
6647 : the symbol for TARGET. */
6648 :
6649 : void
6650 5721 : assemble_alias (tree decl, tree target)
6651 : {
6652 5721 : tree target_decl;
6653 :
6654 5721 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl)))
6655 : {
6656 460 : tree alias = DECL_ASSEMBLER_NAME (decl);
6657 :
6658 460 : ultimate_transparent_alias_target (&target);
6659 :
6660 460 : if (alias == target)
6661 0 : error ("%qs symbol %q+D ultimately targets itself", "weakref", decl);
6662 460 : if (TREE_PUBLIC (decl))
6663 1 : error ("%qs symbol %q+D must have static linkage", "weakref", decl);
6664 : }
6665 : else if (!TARGET_SUPPORTS_ALIASES)
6666 : {
6667 : # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL)
6668 : error_at (DECL_SOURCE_LOCATION (decl),
6669 : "alias definitions not supported in this configuration");
6670 : TREE_ASM_WRITTEN (decl) = 1;
6671 : return;
6672 : # else
6673 : if (!DECL_WEAK (decl))
6674 : {
6675 : /* NB: ifunc_resolver isn't set when an error is detected. */
6676 : if (TREE_CODE (decl) == FUNCTION_DECL
6677 : && lookup_attribute ("ifunc", DECL_ATTRIBUTES (decl)))
6678 : error_at (DECL_SOURCE_LOCATION (decl),
6679 : "%qs is not supported in this configuration", "ifunc");
6680 : else
6681 : error_at (DECL_SOURCE_LOCATION (decl),
6682 : "only weak aliases are supported in this configuration");
6683 : TREE_ASM_WRITTEN (decl) = 1;
6684 : return;
6685 : }
6686 : # endif
6687 : gcc_unreachable ();
6688 : }
6689 5721 : TREE_USED (decl) = 1;
6690 :
6691 : /* Allow aliases to aliases. */
6692 5721 : symtab_node::get_create (decl)->alias = true;
6693 :
6694 : /* If the target has already been emitted, we don't have to queue the
6695 : alias. This saves a tad of memory. */
6696 5721 : if (symtab->global_info_ready)
6697 0 : target_decl = find_decl (target);
6698 : else
6699 : target_decl= NULL;
6700 0 : if ((target_decl && TREE_ASM_WRITTEN (target_decl))
6701 5721 : || symtab->state >= EXPANSION)
6702 0 : do_assemble_alias (decl, target);
6703 : else
6704 : {
6705 5721 : alias_pair p = {decl, target};
6706 5721 : vec_safe_push (alias_pairs, p);
6707 : }
6708 : }
6709 :
6710 : /* Record and output a table of translations from original function
6711 : to its transaction aware clone. Note that tm_pure functions are
6712 : considered to be their own clone. */
6713 :
6714 : struct tm_clone_hasher : ggc_cache_ptr_hash<tree_map>
6715 : {
6716 276 : static hashval_t hash (tree_map *m) { return tree_map_hash (m); }
6717 307 : static bool equal (tree_map *a, tree_map *b) { return tree_map_eq (a, b); }
6718 :
6719 : static int
6720 0 : keep_cache_entry (tree_map *&e)
6721 : {
6722 0 : return ggc_marked_p (e->base.from);
6723 : }
6724 : };
6725 :
6726 : static GTY((cache)) hash_table<tm_clone_hasher> *tm_clone_hash;
6727 :
6728 : void
6729 463 : record_tm_clone_pair (tree o, tree n)
6730 : {
6731 463 : struct tree_map **slot, *h;
6732 :
6733 463 : if (tm_clone_hash == NULL)
6734 165 : tm_clone_hash = hash_table<tm_clone_hasher>::create_ggc (32);
6735 :
6736 463 : h = ggc_alloc<tree_map> ();
6737 463 : h->hash = htab_hash_pointer (o);
6738 463 : h->base.from = o;
6739 463 : h->to = n;
6740 :
6741 463 : slot = tm_clone_hash->find_slot_with_hash (h, h->hash, INSERT);
6742 463 : *slot = h;
6743 463 : }
6744 :
6745 : tree
6746 7 : get_tm_clone_pair (tree o)
6747 : {
6748 7 : if (tm_clone_hash)
6749 : {
6750 7 : struct tree_map *h, in;
6751 :
6752 7 : in.base.from = o;
6753 7 : in.hash = htab_hash_pointer (o);
6754 7 : h = tm_clone_hash->find_with_hash (&in, in.hash);
6755 7 : if (h)
6756 0 : return h->to;
6757 : }
6758 : return NULL_TREE;
6759 : }
6760 :
6761 : struct tm_alias_pair
6762 : {
6763 : unsigned int uid;
6764 : tree from;
6765 : tree to;
6766 : };
6767 :
6768 :
6769 : /* Dump the actual pairs to the .tm_clone_table section. */
6770 :
6771 : static void
6772 148 : dump_tm_clone_pairs (vec<tm_alias_pair> tm_alias_pairs)
6773 : {
6774 148 : unsigned i;
6775 148 : tm_alias_pair *p;
6776 148 : bool switched = false;
6777 :
6778 565 : FOR_EACH_VEC_ELT (tm_alias_pairs, i, p)
6779 : {
6780 417 : tree src = p->from;
6781 417 : tree dst = p->to;
6782 417 : struct cgraph_node *src_n = cgraph_node::get (src);
6783 417 : struct cgraph_node *dst_n = cgraph_node::get (dst);
6784 :
6785 : /* The function ipa_tm_create_version() marks the clone as needed if
6786 : the original function was needed. But we also mark the clone as
6787 : needed if we ever called the clone indirectly through
6788 : TM_GETTMCLONE. If neither of these are true, we didn't generate
6789 : a clone, and we didn't call it indirectly... no sense keeping it
6790 : in the clone table. */
6791 417 : if (!dst_n || !dst_n->definition)
6792 135 : continue;
6793 :
6794 : /* This covers the case where we have optimized the original
6795 : function away, and only access the transactional clone. */
6796 282 : if (!src_n || !src_n->definition)
6797 9 : continue;
6798 :
6799 273 : if (!switched)
6800 : {
6801 120 : switch_to_section (targetm.asm_out.tm_clone_table_section ());
6802 120 : assemble_align (POINTER_SIZE);
6803 120 : switched = true;
6804 : }
6805 :
6806 546 : assemble_integer (XEXP (DECL_RTL (src), 0),
6807 546 : POINTER_SIZE_UNITS, POINTER_SIZE, 1);
6808 546 : assemble_integer (XEXP (DECL_RTL (dst), 0),
6809 546 : POINTER_SIZE_UNITS, POINTER_SIZE, 1);
6810 : }
6811 148 : }
6812 :
6813 : /* Provide a default for the tm_clone_table section. */
6814 :
6815 : section *
6816 120 : default_clone_table_section (void)
6817 : {
6818 120 : return get_named_section (NULL, ".tm_clone_table", 3);
6819 : }
6820 :
6821 : /* Helper comparison function for qsorting by the DECL_UID stored in
6822 : alias_pair->emitted_diags. */
6823 :
6824 : static int
6825 3538 : tm_alias_pair_cmp (const void *x, const void *y)
6826 : {
6827 3538 : const tm_alias_pair *p1 = (const tm_alias_pair *) x;
6828 3538 : const tm_alias_pair *p2 = (const tm_alias_pair *) y;
6829 3538 : if (p1->uid < p2->uid)
6830 : return -1;
6831 1603 : if (p1->uid > p2->uid)
6832 1603 : return 1;
6833 : return 0;
6834 : }
6835 :
6836 : void
6837 243525 : finish_tm_clone_pairs (void)
6838 : {
6839 243525 : vec<tm_alias_pair> tm_alias_pairs = vNULL;
6840 :
6841 243525 : if (tm_clone_hash == NULL)
6842 243377 : return;
6843 :
6844 : /* We need a deterministic order for the .tm_clone_table, otherwise
6845 : we will get bootstrap comparison failures, so dump the hash table
6846 : to a vector, sort it, and dump the vector. */
6847 :
6848 : /* Dump the hashtable to a vector. */
6849 148 : tree_map *map;
6850 148 : hash_table<tm_clone_hasher>::iterator iter;
6851 565 : FOR_EACH_HASH_TABLE_ELEMENT (*tm_clone_hash, map, tree_map *, iter)
6852 : {
6853 417 : tm_alias_pair p = {DECL_UID (map->base.from), map->base.from, map->to};
6854 417 : tm_alias_pairs.safe_push (p);
6855 : }
6856 : /* Sort it. */
6857 148 : tm_alias_pairs.qsort (tm_alias_pair_cmp);
6858 :
6859 : /* Dump it. */
6860 148 : dump_tm_clone_pairs (tm_alias_pairs);
6861 :
6862 148 : tm_clone_hash->empty ();
6863 148 : tm_clone_hash = NULL;
6864 148 : tm_alias_pairs.release ();
6865 : }
6866 :
6867 :
6868 : /* Emit an assembler directive to set symbol for DECL visibility to
6869 : the visibility type VIS, which must not be VISIBILITY_DEFAULT. */
6870 :
6871 : void
6872 33879 : default_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
6873 : int vis ATTRIBUTE_UNUSED)
6874 : {
6875 : #ifdef HAVE_GAS_HIDDEN
6876 33879 : static const char * const visibility_types[] = {
6877 : NULL, "protected", "hidden", "internal"
6878 : };
6879 :
6880 33879 : const char *name, *type;
6881 33879 : tree id;
6882 :
6883 33879 : id = DECL_ASSEMBLER_NAME (decl);
6884 33879 : ultimate_transparent_alias_target (&id);
6885 33879 : name = IDENTIFIER_POINTER (id);
6886 :
6887 33879 : type = visibility_types[vis];
6888 :
6889 33879 : fprintf (asm_out_file, "\t.%s\t", type);
6890 33879 : assemble_name (asm_out_file, name);
6891 33879 : fprintf (asm_out_file, "\n");
6892 : #else
6893 : if (!DECL_ARTIFICIAL (decl))
6894 : warning (OPT_Wattributes, "visibility attribute not supported "
6895 : "in this configuration; ignored");
6896 : #endif
6897 33879 : }
6898 :
6899 : /* A helper function to call assemble_visibility when needed for a decl. */
6900 :
6901 : bool
6902 2918759 : maybe_assemble_visibility (tree decl)
6903 : {
6904 2918759 : enum symbol_visibility vis = DECL_VISIBILITY (decl);
6905 2918759 : if (vis != VISIBILITY_DEFAULT)
6906 : {
6907 32488 : targetm.asm_out.assemble_visibility (decl, vis);
6908 32488 : return true;
6909 : }
6910 : else
6911 : return false;
6912 : }
6913 :
6914 : /* Returns true if the target configuration supports defining public symbols
6915 : so that one of them will be chosen at link time instead of generating a
6916 : multiply-defined symbol error, whether through the use of weak symbols or
6917 : a target-specific mechanism for having duplicates discarded. */
6918 :
6919 : bool
6920 102674 : supports_one_only (void)
6921 : {
6922 102674 : if (SUPPORTS_ONE_ONLY)
6923 102674 : return true;
6924 : if (TARGET_SUPPORTS_WEAK)
6925 : return true;
6926 : return false;
6927 : }
6928 :
6929 : /* Set up DECL as a public symbol that can be defined in multiple
6930 : translation units without generating a linker error. */
6931 :
6932 : void
6933 112768021 : make_decl_one_only (tree decl, tree comdat_group)
6934 : {
6935 112768021 : struct symtab_node *symbol;
6936 112768021 : gcc_assert (VAR_OR_FUNCTION_DECL_P (decl));
6937 :
6938 112768021 : TREE_PUBLIC (decl) = 1;
6939 :
6940 112768021 : symbol = symtab_node::get_create (decl);
6941 :
6942 112768021 : if (SUPPORTS_ONE_ONLY)
6943 : {
6944 : #ifdef MAKE_DECL_ONE_ONLY
6945 112768021 : MAKE_DECL_ONE_ONLY (decl);
6946 : #endif
6947 112768021 : symbol->set_comdat_group (comdat_group);
6948 : }
6949 : else if (VAR_P (decl)
6950 : && (DECL_INITIAL (decl) == 0
6951 : || (!in_lto_p && DECL_INITIAL (decl) == error_mark_node)))
6952 : DECL_COMMON (decl) = 1;
6953 : else
6954 : {
6955 : gcc_assert (TARGET_SUPPORTS_WEAK);
6956 : DECL_WEAK (decl) = 1;
6957 : }
6958 112768021 : }
6959 :
6960 : void
6961 295425 : init_varasm_once (void)
6962 : {
6963 295425 : section_htab = hash_table<section_hasher>::create_ggc (31);
6964 295425 : object_block_htab = hash_table<object_block_hasher>::create_ggc (31);
6965 295425 : const_desc_htab = hash_table<tree_descriptor_hasher>::create_ggc (1009);
6966 :
6967 295425 : shared_constant_pool = create_constant_pool ();
6968 :
6969 : #ifdef TEXT_SECTION_ASM_OP
6970 295425 : text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op,
6971 : TEXT_SECTION_ASM_OP);
6972 : #endif
6973 :
6974 : #ifdef DATA_SECTION_ASM_OP
6975 295425 : data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6976 : DATA_SECTION_ASM_OP);
6977 : #endif
6978 :
6979 : #ifdef SDATA_SECTION_ASM_OP
6980 : sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op,
6981 : SDATA_SECTION_ASM_OP);
6982 : #endif
6983 :
6984 : #ifdef READONLY_DATA_SECTION_ASM_OP
6985 295425 : readonly_data_section = get_unnamed_section (0, output_section_asm_op,
6986 : READONLY_DATA_SECTION_ASM_OP);
6987 : #endif
6988 :
6989 : #ifdef CTORS_SECTION_ASM_OP
6990 : ctors_section = get_unnamed_section (0, output_section_asm_op,
6991 : CTORS_SECTION_ASM_OP);
6992 : #endif
6993 :
6994 : #ifdef DTORS_SECTION_ASM_OP
6995 : dtors_section = get_unnamed_section (0, output_section_asm_op,
6996 : DTORS_SECTION_ASM_OP);
6997 : #endif
6998 :
6999 : #ifdef BSS_SECTION_ASM_OP
7000 295425 : bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
7001 : output_section_asm_op,
7002 : BSS_SECTION_ASM_OP);
7003 : #endif
7004 :
7005 : #ifdef SBSS_SECTION_ASM_OP
7006 : sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS,
7007 : output_section_asm_op,
7008 : SBSS_SECTION_ASM_OP);
7009 : #endif
7010 :
7011 295425 : tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
7012 : | SECTION_COMMON, emit_tls_common);
7013 295425 : lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
7014 : | SECTION_COMMON, emit_local);
7015 295425 : comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS
7016 : | SECTION_COMMON, emit_common);
7017 :
7018 : #if defined ASM_OUTPUT_ALIGNED_BSS
7019 295425 : bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS,
7020 : emit_bss);
7021 : #endif
7022 :
7023 295425 : targetm.asm_out.init_sections ();
7024 :
7025 295425 : if (readonly_data_section == NULL)
7026 0 : readonly_data_section = text_section;
7027 :
7028 : #ifdef ASM_OUTPUT_EXTERNAL
7029 295425 : pending_assemble_externals_set = new hash_set<tree>;
7030 : #endif
7031 295425 : }
7032 :
7033 : /* Determine whether SYMBOL is used in any optimized function. */
7034 :
7035 : static bool
7036 180 : have_optimized_refs (struct symtab_node *symbol)
7037 : {
7038 180 : struct ipa_ref *ref;
7039 :
7040 204 : for (int i = 0; symbol->iterate_referring (i, ref); i++)
7041 : {
7042 220 : cgraph_node *cnode = dyn_cast <cgraph_node *> (ref->referring);
7043 :
7044 196 : if (cnode && opt_for_fn (cnode->decl, optimize))
7045 : return true;
7046 : }
7047 :
7048 : return false;
7049 : }
7050 :
7051 : /* Check if promoting general-dynamic TLS access model to local-dynamic is
7052 : desirable for DECL. */
7053 :
7054 : static bool
7055 327 : optimize_dyn_tls_for_decl_p (const_tree decl)
7056 : {
7057 327 : if (cfun)
7058 30 : return optimize;
7059 297 : return symtab->state >= IPA && have_optimized_refs (symtab_node::get (decl));
7060 : }
7061 :
7062 :
7063 : enum tls_model
7064 28983 : decl_default_tls_model (const_tree decl)
7065 : {
7066 28983 : enum tls_model kind;
7067 28983 : bool is_local;
7068 :
7069 28983 : is_local = targetm.binds_local_p (decl);
7070 28983 : if (!flag_shlib)
7071 : {
7072 26541 : if (is_local)
7073 : kind = TLS_MODEL_LOCAL_EXEC;
7074 : else
7075 20461 : kind = TLS_MODEL_INITIAL_EXEC;
7076 : }
7077 :
7078 : /* Local dynamic is inefficient when we're not combining the
7079 : parts of the address. */
7080 2442 : else if (is_local && optimize_dyn_tls_for_decl_p (decl))
7081 : kind = TLS_MODEL_LOCAL_DYNAMIC;
7082 : else
7083 : kind = TLS_MODEL_GLOBAL_DYNAMIC;
7084 28983 : if (kind < flag_tls_default)
7085 182 : kind = flag_tls_default;
7086 :
7087 28983 : return kind;
7088 : }
7089 :
7090 : /* Select a set of attributes for section NAME based on the properties
7091 : of DECL and whether or not RELOC indicates that DECL's initializer
7092 : might contain runtime relocations.
7093 :
7094 : We make the section read-only and executable for a function decl,
7095 : read-only for a const data decl, and writable for a non-const data decl. */
7096 :
7097 : unsigned int
7098 70683050 : default_section_type_flags (tree decl, const char *name, int reloc)
7099 : {
7100 70683050 : unsigned int flags;
7101 :
7102 70683050 : if (decl && TREE_CODE (decl) == FUNCTION_DECL)
7103 : flags = SECTION_CODE;
7104 2981054 : else if (strcmp (name, ".data.rel.ro") == 0
7105 2980933 : || strcmp (name, ".data.rel.ro.local") == 0)
7106 : flags = SECTION_WRITE | SECTION_RELRO;
7107 2980522 : else if (decl)
7108 : {
7109 2980402 : enum section_category category
7110 2980402 : = categorize_decl_for_section (decl, reloc);
7111 6608277 : if (decl_readonly_section_1 (category))
7112 : flags = 0;
7113 646941 : else if (category == SECCAT_DATA_REL_RO
7114 646941 : || category == SECCAT_DATA_REL_RO_LOCAL)
7115 : flags = SECTION_WRITE | SECTION_RELRO;
7116 : else
7117 2980934 : flags = SECTION_WRITE;
7118 : }
7119 : else
7120 : flags = SECTION_WRITE;
7121 :
7122 70682930 : if (decl && DECL_P (decl) && DECL_COMDAT_GROUP (decl))
7123 39228220 : flags |= SECTION_LINKONCE;
7124 :
7125 70683050 : if (strcmp (name, ".vtable_map_vars") == 0)
7126 6 : flags |= SECTION_LINKONCE;
7127 :
7128 70683050 : if (decl && VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
7129 3909 : flags |= SECTION_TLS | SECTION_WRITE;
7130 :
7131 70683050 : if (strcmp (name, ".bss") == 0
7132 70683050 : || startswith (name, ".bss.")
7133 70668535 : || startswith (name, ".gnu.linkonce.b.")
7134 70668535 : || strcmp (name, ".persistent.bss") == 0
7135 70668535 : || strcmp (name, ".sbss") == 0
7136 70668535 : || startswith (name, ".sbss.")
7137 141351585 : || startswith (name, ".gnu.linkonce.sb."))
7138 14515 : flags |= SECTION_BSS;
7139 :
7140 70683050 : if (strcmp (name, ".tdata") == 0
7141 70682736 : || startswith (name, ".tdata.")
7142 141365747 : || startswith (name, ".gnu.linkonce.td."))
7143 353 : flags |= SECTION_TLS;
7144 :
7145 70683050 : if (strcmp (name, ".tbss") == 0
7146 70679688 : || startswith (name, ".tbss.")
7147 141362550 : || startswith (name, ".gnu.linkonce.tb."))
7148 3550 : flags |= SECTION_TLS | SECTION_BSS;
7149 :
7150 70683050 : if (strcmp (name, ".noinit") == 0)
7151 0 : flags |= SECTION_WRITE | SECTION_BSS | SECTION_NOTYPE;
7152 :
7153 70683050 : if (strcmp (name, ".persistent") == 0)
7154 0 : flags |= SECTION_WRITE | SECTION_NOTYPE;
7155 :
7156 : /* Various sections have special ELF types that the assembler will
7157 : assign by default based on the name. They are neither SHT_PROGBITS
7158 : nor SHT_NOBITS, so when changing sections we don't want to print a
7159 : section type (@progbits or @nobits). Rather than duplicating the
7160 : assembler's knowledge of what those special name patterns are, just
7161 : let the assembler choose the type if we don't know a specific
7162 : reason to set it to something other than the default. SHT_PROGBITS
7163 : is the default for sections whose name is not specially known to
7164 : the assembler, so it does no harm to leave the choice to the
7165 : assembler when @progbits is the best thing we know to use. If
7166 : someone is silly enough to emit code or TLS variables to one of
7167 : these sections, then don't handle them specially.
7168 :
7169 : default_elf_asm_named_section (below) handles the BSS, TLS, ENTSIZE, and
7170 : LINKONCE cases when NOTYPE is not set, so leave those to its logic. */
7171 70683050 : if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS | SECTION_ENTSIZE))
7172 2962630 : && !(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)))
7173 2407924 : flags |= SECTION_NOTYPE;
7174 :
7175 70683050 : return flags;
7176 : }
7177 :
7178 : /* Return true if the target supports some form of global BSS,
7179 : either through bss_noswitch_section, or by selecting a BSS
7180 : section in TARGET_ASM_SELECT_SECTION. */
7181 :
7182 : bool
7183 0 : have_global_bss_p (void)
7184 : {
7185 0 : return bss_noswitch_section || targetm.have_switchable_bss_sections;
7186 : }
7187 :
7188 : /* Output assembly to switch to section NAME with attribute FLAGS.
7189 : Four variants for common object file formats. */
7190 :
7191 : void
7192 0 : default_no_named_section (const char *name ATTRIBUTE_UNUSED,
7193 : unsigned int flags ATTRIBUTE_UNUSED,
7194 : tree decl ATTRIBUTE_UNUSED)
7195 : {
7196 : /* Some object formats don't support named sections at all. The
7197 : front-end should already have flagged this as an error. */
7198 0 : gcc_unreachable ();
7199 : }
7200 :
7201 : #ifndef TLS_SECTION_ASM_FLAG
7202 : #define TLS_SECTION_ASM_FLAG 'T'
7203 : #endif
7204 :
7205 : void
7206 3689922 : default_elf_asm_named_section (const char *name, unsigned int flags,
7207 : tree decl)
7208 : {
7209 3689922 : char flagchars[11], *f = flagchars;
7210 3689922 : unsigned int numeric_value = 0;
7211 :
7212 : /* If we have already declared this section, we can use an
7213 : abbreviated form to switch back to it -- unless this section is
7214 : part of a COMDAT groups or with SHF_GNU_RETAIN or with SHF_LINK_ORDER,
7215 : in which case GAS requires the full declaration every time. */
7216 3689922 : if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7217 3101648 : && !(flags & (SECTION_RETAIN | SECTION_LINK_ORDER))
7218 3101344 : && (flags & SECTION_DECLARED))
7219 : {
7220 396824 : fprintf (asm_out_file, "\t.section\t%s\n", name);
7221 396824 : return;
7222 : }
7223 :
7224 : /* If we have a machine specific flag, then use the numeric value to pass
7225 : this on to GAS. */
7226 3293098 : if (targetm.asm_out.elf_flags_numeric (flags, &numeric_value))
7227 0 : snprintf (f, sizeof (flagchars), "0x%08x", numeric_value);
7228 : else
7229 : {
7230 3293098 : if (!(flags & SECTION_DEBUG))
7231 2159219 : *f++ = 'a';
7232 : #if HAVE_GAS_SECTION_EXCLUDE
7233 3293098 : if (flags & SECTION_EXCLUDE)
7234 482978 : *f++ = 'e';
7235 : #endif
7236 3293098 : if (flags & SECTION_WRITE)
7237 360117 : *f++ = 'w';
7238 3293098 : if (flags & SECTION_CODE)
7239 400345 : *f++ = 'x';
7240 3293098 : if (flags & SECTION_SMALL)
7241 0 : *f++ = 's';
7242 3293098 : if (flags & SECTION_MERGE)
7243 227218 : *f++ = 'M';
7244 3293098 : if (flags & SECTION_STRINGS)
7245 186578 : *f++ = 'S';
7246 3293098 : if (flags & SECTION_TLS)
7247 1280 : *f++ = TLS_SECTION_ASM_FLAG;
7248 3293098 : if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7249 588274 : *f++ = 'G';
7250 3293098 : if (flags & SECTION_RETAIN)
7251 259 : *f++ = 'R';
7252 3293098 : if (flags & SECTION_LINK_ORDER)
7253 57 : *f++ = 'o';
7254 : #ifdef MACH_DEP_SECTION_ASM_FLAG
7255 3293098 : if (flags & SECTION_MACH_DEP)
7256 12 : *f++ = MACH_DEP_SECTION_ASM_FLAG;
7257 : #endif
7258 3293098 : *f = '\0';
7259 : }
7260 :
7261 3293098 : fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
7262 :
7263 : /* default_section_type_flags (above) knows which flags need special
7264 : handling here, and sets NOTYPE when none of these apply so that the
7265 : assembler's logic for default types can apply to user-chosen
7266 : section names. */
7267 3293098 : if (!(flags & SECTION_NOTYPE))
7268 : {
7269 2038889 : const char *type;
7270 2038889 : const char *format;
7271 :
7272 2038889 : if (flags & SECTION_BSS)
7273 : type = "nobits";
7274 : else
7275 2025246 : type = "progbits";
7276 :
7277 2038889 : format = ",@%s";
7278 : /* On platforms that use "@" as the assembly comment character,
7279 : use "%" instead. */
7280 2038889 : if (strcmp (ASM_COMMENT_START, "@") == 0)
7281 : format = ",%%%s";
7282 2038889 : fprintf (asm_out_file, format, type);
7283 :
7284 2038889 : if (flags & SECTION_ENTSIZE)
7285 227218 : fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
7286 2038889 : if (flags & SECTION_LINK_ORDER)
7287 : {
7288 : /* For now, only section "__patchable_function_entries"
7289 : adopts flag SECTION_LINK_ORDER, internal label LPFE*
7290 : was emitted in default_print_patchable_function_entry,
7291 : just place it here for linked_to section. */
7292 57 : gcc_assert (!strcmp (name, "__patchable_function_entries"));
7293 57 : fprintf (asm_out_file, ",");
7294 57 : char buf[256];
7295 57 : ASM_GENERATE_INTERNAL_LABEL (buf, "LPFE",
7296 : current_function_funcdef_no);
7297 57 : assemble_name_raw (asm_out_file, buf);
7298 : }
7299 2038889 : if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE))
7300 : {
7301 588274 : if (TREE_CODE (decl) == IDENTIFIER_NODE)
7302 1640 : fprintf (asm_out_file, ",%s,comdat", IDENTIFIER_POINTER (decl));
7303 : else
7304 1173268 : fprintf (asm_out_file, ",%s,comdat",
7305 586634 : IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)));
7306 : }
7307 : }
7308 :
7309 3293098 : putc ('\n', asm_out_file);
7310 : }
7311 :
7312 : void
7313 0 : default_coff_asm_named_section (const char *name, unsigned int flags,
7314 : tree decl ATTRIBUTE_UNUSED)
7315 : {
7316 0 : char flagchars[8], *f = flagchars;
7317 :
7318 0 : if (flags & SECTION_WRITE)
7319 0 : *f++ = 'w';
7320 0 : if (flags & SECTION_CODE)
7321 0 : *f++ = 'x';
7322 0 : *f = '\0';
7323 :
7324 0 : fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars);
7325 0 : }
7326 :
7327 : void
7328 0 : default_pe_asm_named_section (const char *name, unsigned int flags,
7329 : tree decl)
7330 : {
7331 0 : default_coff_asm_named_section (name, flags, decl);
7332 :
7333 0 : if (flags & SECTION_LINKONCE)
7334 : {
7335 : /* Functions may have been compiled at various levels of
7336 : optimization so we can't use `same_size' here.
7337 : Instead, have the linker pick one. */
7338 0 : fprintf (asm_out_file, "\t.linkonce %s\n",
7339 0 : (flags & SECTION_CODE ? "discard" : "same_size"));
7340 : }
7341 0 : }
7342 :
7343 : /* The lame default section selector. */
7344 :
7345 : section *
7346 0 : default_select_section (tree decl, int reloc,
7347 : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
7348 : {
7349 0 : if (DECL_P (decl))
7350 : {
7351 0 : if (decl_readonly_section (decl, reloc))
7352 0 : return readonly_data_section;
7353 : }
7354 0 : else if (TREE_CODE (decl) == CONSTRUCTOR)
7355 : {
7356 0 : if (! ((flag_pic && reloc)
7357 0 : || !TREE_READONLY (decl)
7358 0 : || !TREE_CONSTANT (decl)))
7359 0 : return readonly_data_section;
7360 : }
7361 0 : else if (TREE_CODE (decl) == STRING_CST)
7362 0 : return readonly_data_section;
7363 0 : else if (! (flag_pic && reloc))
7364 0 : return readonly_data_section;
7365 :
7366 0 : return data_section;
7367 : }
7368 :
7369 : enum section_category
7370 6518880 : categorize_decl_for_section (const_tree decl, int reloc)
7371 : {
7372 6518880 : enum section_category ret;
7373 :
7374 6518880 : if (TREE_CODE (decl) == FUNCTION_DECL)
7375 : return SECCAT_TEXT;
7376 6265253 : else if (TREE_CODE (decl) == STRING_CST)
7377 : {
7378 1281084 : if ((flag_sanitize & SANITIZE_ADDRESS)
7379 1281084 : && asan_protect_global (const_cast<tree> (decl)))
7380 : /* or !flag_merge_constants */
7381 : return SECCAT_RODATA;
7382 : else
7383 1279137 : return SECCAT_RODATA_MERGE_STR;
7384 : }
7385 4984169 : else if (VAR_P (decl))
7386 : {
7387 4953182 : tree d = const_cast<tree> (decl);
7388 4953182 : if (bss_initializer_p (decl))
7389 : ret = SECCAT_BSS;
7390 4916864 : else if (! TREE_READONLY (decl)
7391 4916864 : || (DECL_INITIAL (decl)
7392 4580367 : && ! TREE_CONSTANT (DECL_INITIAL (decl))))
7393 : {
7394 : /* Here the reloc_rw_mask is not testing whether the section should
7395 : be read-only or not, but whether the dynamic link will have to
7396 : do something. If so, we wish to segregate the data in order to
7397 : minimize cache misses inside the dynamic linker. */
7398 341869 : if (reloc & targetm.asm_out.reloc_rw_mask ())
7399 11737 : ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
7400 : else
7401 : ret = SECCAT_DATA;
7402 : }
7403 4574995 : else if (reloc & targetm.asm_out.reloc_rw_mask ())
7404 922359 : ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
7405 751527 : else if (reloc || (flag_merge_constants < 2 && !DECL_MERGEABLE (decl))
7406 3655120 : || ((flag_sanitize & SANITIZE_ADDRESS)
7407 : /* PR 81697: for architectures that use section anchors we
7408 : need to ignore DECL_RTL_SET_P (decl) for string constants
7409 : inside this asan_protect_global call because otherwise
7410 : we'll wrongly put them into SECCAT_RODATA_MERGE_CONST
7411 : section, set DECL_RTL (decl) later on and add DECL to
7412 : protected globals via successive asan_protect_global
7413 : calls. In this scenario we'll end up with wrong
7414 : alignment of these strings at runtime and possible ASan
7415 : false positives. */
7416 182 : && asan_protect_global (d, use_object_blocks_p ()
7417 0 : && use_blocks_for_decl_p (d))))
7418 : /* C and C++ don't allow different variables to share the same
7419 : location. -fmerge-all-constants allows even that (at the
7420 : expense of not conforming). */
7421 : ret = SECCAT_RODATA;
7422 2405 : else if (DECL_INITIAL (decl)
7423 2405 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST)
7424 : ret = SECCAT_RODATA_MERGE_STR_INIT;
7425 : else
7426 : ret = SECCAT_RODATA_MERGE_CONST;
7427 : }
7428 30987 : else if (TREE_CODE (decl) == CONSTRUCTOR)
7429 : {
7430 1554 : if ((reloc & targetm.asm_out.reloc_rw_mask ())
7431 1554 : || ! TREE_CONSTANT (decl))
7432 : ret = SECCAT_DATA;
7433 : else
7434 : ret = SECCAT_RODATA;
7435 : }
7436 : else
7437 : ret = SECCAT_RODATA;
7438 :
7439 : /* There are no read-only thread-local sections. */
7440 4984169 : if (VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
7441 : {
7442 : /* Note that this would be *just* SECCAT_BSS, except that there's
7443 : no concept of a read-only thread-local-data section. */
7444 7810 : if (ret == SECCAT_BSS
7445 712 : || DECL_INITIAL (decl) == NULL
7446 8516 : || (flag_zero_initialized_in_bss
7447 706 : && initializer_zerop (DECL_INITIAL (decl))))
7448 : ret = SECCAT_TBSS;
7449 : else
7450 : ret = SECCAT_TDATA;
7451 : }
7452 :
7453 : /* If the target uses small data sections, select it. */
7454 4976359 : else if (targetm.in_small_data_p (decl))
7455 : {
7456 0 : if (ret == SECCAT_BSS)
7457 : ret = SECCAT_SBSS;
7458 0 : else if (targetm.have_srodata_section && ret == SECCAT_RODATA)
7459 : ret = SECCAT_SRODATA;
7460 : else
7461 0 : ret = SECCAT_SDATA;
7462 : }
7463 :
7464 : return ret;
7465 : }
7466 :
7467 : static bool
7468 3004345 : decl_readonly_section_1 (enum section_category category)
7469 : {
7470 2980402 : switch (category)
7471 : {
7472 : case SECCAT_RODATA:
7473 : case SECCAT_RODATA_MERGE_STR:
7474 : case SECCAT_RODATA_MERGE_STR_INIT:
7475 : case SECCAT_RODATA_MERGE_CONST:
7476 : case SECCAT_SRODATA:
7477 : return true;
7478 649540 : default:
7479 649540 : return false;
7480 : }
7481 : }
7482 :
7483 : bool
7484 23943 : decl_readonly_section (const_tree decl, int reloc)
7485 : {
7486 23943 : return decl_readonly_section_1 (categorize_decl_for_section (decl, reloc));
7487 : }
7488 :
7489 : /* Select a section based on the above categorization. */
7490 :
7491 : section *
7492 1691944 : default_elf_select_section (tree decl, int reloc,
7493 : unsigned HOST_WIDE_INT align)
7494 : {
7495 1691944 : const char *sname;
7496 :
7497 1691944 : switch (categorize_decl_for_section (decl, reloc))
7498 : {
7499 0 : case SECCAT_TEXT:
7500 : /* We're not supposed to be called on FUNCTION_DECLs. */
7501 0 : gcc_unreachable ();
7502 140683 : case SECCAT_RODATA:
7503 140683 : return readonly_data_section;
7504 1257962 : case SECCAT_RODATA_MERGE_STR:
7505 1257962 : return mergeable_string_section (decl, align, 0);
7506 14 : case SECCAT_RODATA_MERGE_STR_INIT:
7507 14 : return mergeable_string_section (DECL_INITIAL (decl), align, 0);
7508 481 : case SECCAT_RODATA_MERGE_CONST:
7509 481 : return mergeable_constant_section (DECL_SIZE (decl), align, 0);
7510 : case SECCAT_SRODATA:
7511 : sname = ".sdata2";
7512 : break;
7513 287734 : case SECCAT_DATA:
7514 287734 : if (DECL_P (decl) && DECL_PERSISTENT_P (decl))
7515 : {
7516 : sname = ".persistent";
7517 : break;
7518 : }
7519 287734 : return data_section;
7520 146 : case SECCAT_DATA_REL:
7521 146 : sname = ".data.rel";
7522 146 : break;
7523 969 : case SECCAT_DATA_REL_LOCAL:
7524 969 : sname = ".data.rel.local";
7525 969 : break;
7526 107 : case SECCAT_DATA_REL_RO:
7527 107 : sname = ".data.rel.ro";
7528 107 : break;
7529 167 : case SECCAT_DATA_REL_RO_LOCAL:
7530 167 : sname = ".data.rel.ro.local";
7531 167 : break;
7532 0 : case SECCAT_SDATA:
7533 0 : sname = ".sdata";
7534 0 : break;
7535 314 : case SECCAT_TDATA:
7536 314 : sname = ".tdata";
7537 314 : break;
7538 5 : case SECCAT_BSS:
7539 5 : if (DECL_P (decl) && DECL_NOINIT_P (decl))
7540 : {
7541 : sname = ".noinit";
7542 : break;
7543 : }
7544 5 : if (bss_section)
7545 : return bss_section;
7546 : sname = ".bss";
7547 : break;
7548 0 : case SECCAT_SBSS:
7549 0 : sname = ".sbss";
7550 0 : break;
7551 3362 : case SECCAT_TBSS:
7552 3362 : sname = ".tbss";
7553 3362 : break;
7554 0 : default:
7555 0 : gcc_unreachable ();
7556 : }
7557 :
7558 5065 : return get_named_section (decl, sname, reloc);
7559 : }
7560 :
7561 : /* Construct a unique section name based on the decl name and the
7562 : categorization performed above. */
7563 :
7564 : void
7565 1822487 : default_unique_section (tree decl, int reloc)
7566 : {
7567 : /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */
7568 1822487 : bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP;
7569 1822487 : const char *prefix, *name, *linkonce;
7570 1822487 : char *string;
7571 1822487 : tree id;
7572 :
7573 1822487 : switch (categorize_decl_for_section (decl, reloc))
7574 : {
7575 : case SECCAT_TEXT:
7576 : prefix = one_only ? ".t" : ".text";
7577 : break;
7578 1210685 : case SECCAT_RODATA:
7579 1210685 : case SECCAT_RODATA_MERGE_STR:
7580 1210685 : case SECCAT_RODATA_MERGE_STR_INIT:
7581 1210685 : case SECCAT_RODATA_MERGE_CONST:
7582 1210685 : prefix = one_only ? ".r" : ".rodata";
7583 : break;
7584 0 : case SECCAT_SRODATA:
7585 0 : prefix = one_only ? ".s2" : ".sdata2";
7586 : break;
7587 15396 : case SECCAT_DATA:
7588 15396 : prefix = one_only ? ".d" : ".data";
7589 15396 : if (DECL_P (decl) && DECL_PERSISTENT_P (decl))
7590 : {
7591 : prefix = one_only ? ".p" : ".persistent";
7592 : break;
7593 : }
7594 : break;
7595 1137 : case SECCAT_DATA_REL:
7596 1137 : prefix = one_only ? ".d.rel" : ".data.rel";
7597 : break;
7598 3641 : case SECCAT_DATA_REL_LOCAL:
7599 3641 : prefix = one_only ? ".d.rel.local" : ".data.rel.local";
7600 : break;
7601 156090 : case SECCAT_DATA_REL_RO:
7602 156090 : prefix = one_only ? ".d.rel.ro" : ".data.rel.ro";
7603 : break;
7604 168648 : case SECCAT_DATA_REL_RO_LOCAL:
7605 168648 : prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local";
7606 : break;
7607 0 : case SECCAT_SDATA:
7608 0 : prefix = one_only ? ".s" : ".sdata";
7609 : break;
7610 13039 : case SECCAT_BSS:
7611 13039 : if (DECL_P (decl) && DECL_NOINIT_P (decl))
7612 : {
7613 : prefix = one_only ? ".n" : ".noinit";
7614 : break;
7615 : }
7616 : prefix = one_only ? ".b" : ".bss";
7617 : break;
7618 0 : case SECCAT_SBSS:
7619 0 : prefix = one_only ? ".sb" : ".sbss";
7620 : break;
7621 39 : case SECCAT_TDATA:
7622 39 : prefix = one_only ? ".td" : ".tdata";
7623 : break;
7624 186 : case SECCAT_TBSS:
7625 186 : prefix = one_only ? ".tb" : ".tbss";
7626 : break;
7627 0 : default:
7628 0 : gcc_unreachable ();
7629 : }
7630 :
7631 1822487 : id = DECL_ASSEMBLER_NAME (decl);
7632 1822487 : ultimate_transparent_alias_target (&id);
7633 1822487 : name = IDENTIFIER_POINTER (id);
7634 1822487 : name = targetm.strip_name_encoding (name);
7635 :
7636 : /* If we're using one_only, then there needs to be a .gnu.linkonce
7637 : prefix to the section name. */
7638 1822487 : linkonce = one_only ? ".gnu.linkonce" : "";
7639 :
7640 1822487 : string = ACONCAT ((linkonce, prefix, ".", name, NULL));
7641 :
7642 1822487 : set_decl_section_name (decl, string);
7643 1822487 : }
7644 :
7645 : /* Subroutine of compute_reloc_for_rtx for leaf rtxes. */
7646 :
7647 : static int
7648 39118 : compute_reloc_for_rtx_1 (const_rtx x)
7649 : {
7650 39118 : switch (GET_CODE (x))
7651 : {
7652 28205 : case SYMBOL_REF:
7653 28205 : return SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
7654 : case LABEL_REF:
7655 : return 1;
7656 : default:
7657 : return 0;
7658 : }
7659 : }
7660 :
7661 : /* Like compute_reloc_for_constant, except for an RTX. The return value
7662 : is a mask for which bit 1 indicates a global relocation, and bit 0
7663 : indicates a local relocation. Used by default_select_rtx_section
7664 : and default_elf_select_rtx_section. */
7665 :
7666 : static int
7667 251568 : compute_reloc_for_rtx (const_rtx x)
7668 : {
7669 251568 : switch (GET_CODE (x))
7670 : {
7671 24618 : case SYMBOL_REF:
7672 24618 : case LABEL_REF:
7673 24618 : return compute_reloc_for_rtx_1 (x);
7674 :
7675 3625 : case CONST:
7676 3625 : {
7677 3625 : int reloc = 0;
7678 3625 : subrtx_iterator::array_type array;
7679 18125 : FOR_EACH_SUBRTX (iter, array, x, ALL)
7680 14500 : reloc |= compute_reloc_for_rtx_1 (*iter);
7681 3625 : return reloc;
7682 3625 : }
7683 :
7684 : default:
7685 : return 0;
7686 : }
7687 : }
7688 :
7689 : section *
7690 0 : default_select_rtx_section (machine_mode mode ATTRIBUTE_UNUSED,
7691 : rtx x,
7692 : unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
7693 : {
7694 0 : if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ())
7695 0 : return data_section;
7696 : else
7697 0 : return readonly_data_section;
7698 : }
7699 :
7700 : section *
7701 251568 : default_elf_select_rtx_section (machine_mode mode, rtx x,
7702 : unsigned HOST_WIDE_INT align)
7703 : {
7704 251568 : int reloc = compute_reloc_for_rtx (x);
7705 251568 : tree decl = nullptr;
7706 251568 : const char *prefix = nullptr;
7707 251568 : int flags = 0;
7708 :
7709 : /* If it is a private COMDAT function symbol reference, call
7710 : function_rodata_section for the read-only or relocated read-only
7711 : data section associated with function DECL so that the COMDAT
7712 : section will be used for the private COMDAT function symbol. */
7713 251568 : if (HAVE_COMDAT_GROUP)
7714 : {
7715 251568 : if (GET_CODE (x) == CONST
7716 3625 : && GET_CODE (XEXP (x, 0)) == PLUS
7717 3625 : && CONST_INT_P (XEXP (XEXP (x, 0), 1)))
7718 3625 : x = XEXP (XEXP (x, 0), 0);
7719 :
7720 251568 : if (GET_CODE (x) == SYMBOL_REF)
7721 : {
7722 28205 : decl = SYMBOL_REF_DECL (x);
7723 28205 : if (decl
7724 28205 : && (TREE_CODE (decl) != FUNCTION_DECL
7725 7396 : || !DECL_COMDAT_GROUP (decl)
7726 5337 : || TREE_PUBLIC (decl)))
7727 : decl = nullptr;
7728 : }
7729 : }
7730 :
7731 : /* ??? Handle small data here somehow. */
7732 :
7733 251568 : if (reloc & targetm.asm_out.reloc_rw_mask ())
7734 : {
7735 250 : if (decl)
7736 : {
7737 0 : prefix = reloc == 1 ? ".data.rel.ro.local" : ".data.rel.ro";
7738 : flags = SECTION_WRITE | SECTION_RELRO;
7739 : }
7740 250 : else if (reloc == 1)
7741 244 : return get_named_section (NULL, ".data.rel.ro.local", 1);
7742 : else
7743 6 : return get_named_section (NULL, ".data.rel.ro", 3);
7744 : }
7745 :
7746 251318 : if (decl)
7747 : {
7748 16 : const char *comdat = IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl));
7749 16 : if (!prefix)
7750 16 : prefix = ".rodata";
7751 16 : size_t prefix_len = strlen (prefix);
7752 16 : size_t comdat_len = strlen (comdat);
7753 16 : size_t len = prefix_len + sizeof (".pool.") + comdat_len;
7754 16 : char *name = XALLOCAVEC (char, len);
7755 16 : memcpy (name, prefix, prefix_len);
7756 16 : memcpy (name + prefix_len, ".pool.", sizeof (".pool.") - 1);
7757 16 : memcpy (name + prefix_len + sizeof (".pool.") - 1, comdat,
7758 : comdat_len + 1);
7759 16 : return get_section (name, flags | SECTION_LINKONCE, decl);
7760 : }
7761 :
7762 251302 : return mergeable_constant_section (mode, align, 0);
7763 : }
7764 :
7765 : /* Set the generally applicable flags on the SYMBOL_REF for EXP. */
7766 :
7767 : void
7768 10172325 : default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
7769 : {
7770 10172325 : rtx symbol;
7771 10172325 : int flags;
7772 :
7773 : /* Careful not to prod global register variables. */
7774 10172325 : if (!MEM_P (rtl))
7775 : return;
7776 10172325 : symbol = XEXP (rtl, 0);
7777 10172325 : if (GET_CODE (symbol) != SYMBOL_REF)
7778 : return;
7779 :
7780 10172325 : flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO;
7781 10172325 : if (TREE_CODE (decl) == FUNCTION_DECL)
7782 5588970 : flags |= SYMBOL_FLAG_FUNCTION;
7783 10172325 : if (targetm.binds_local_p (decl))
7784 5742054 : flags |= SYMBOL_FLAG_LOCAL;
7785 10172325 : if (VAR_P (decl) && DECL_THREAD_LOCAL_P (decl))
7786 4642 : flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT;
7787 10167683 : else if (targetm.in_small_data_p (decl))
7788 0 : flags |= SYMBOL_FLAG_SMALL;
7789 : /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without
7790 : being PUBLIC, the thing *must* be defined in this translation unit.
7791 : Prevent this buglet from being propagated into rtl code as well. */
7792 10172325 : if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
7793 4269703 : flags |= SYMBOL_FLAG_EXTERNAL;
7794 :
7795 10172325 : SYMBOL_REF_FLAGS (symbol) = flags;
7796 : }
7797 :
7798 : /* By default, we do nothing for encode_section_info, so we need not
7799 : do anything but discard the '*' marker. */
7800 :
7801 : const char *
7802 421633318 : default_strip_name_encoding (const char *str)
7803 : {
7804 421633318 : return str + (*str == '*');
7805 : }
7806 :
7807 : #ifdef ASM_OUTPUT_DEF
7808 : /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the
7809 : anchor relative to ".", the current section position. */
7810 :
7811 : void
7812 0 : default_asm_output_anchor (rtx symbol)
7813 : {
7814 0 : gcc_checking_assert (TARGET_SUPPORTS_ALIASES);
7815 :
7816 0 : char buffer[100];
7817 :
7818 0 : sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC,
7819 : SYMBOL_REF_BLOCK_OFFSET (symbol));
7820 0 : ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer);
7821 0 : }
7822 : #endif
7823 :
7824 : /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */
7825 :
7826 : bool
7827 0 : default_use_anchors_for_symbol_p (const_rtx symbol)
7828 : {
7829 0 : tree decl;
7830 0 : section *sect = SYMBOL_REF_BLOCK (symbol)->sect;
7831 :
7832 : /* This function should only be called with non-zero SYMBOL_REF_BLOCK,
7833 : furthermore get_block_for_section should not create object blocks
7834 : for mergeable sections. */
7835 0 : gcc_checking_assert (sect && !(sect->common.flags & SECTION_MERGE));
7836 :
7837 : /* Don't use anchors for small data sections. The small data register
7838 : acts as an anchor for such sections. */
7839 0 : if (sect->common.flags & SECTION_SMALL)
7840 : return false;
7841 :
7842 0 : decl = SYMBOL_REF_DECL (symbol);
7843 0 : if (decl && DECL_P (decl))
7844 : {
7845 : /* Don't use section anchors for decls that might be defined or
7846 : usurped by other modules. */
7847 0 : if (TREE_PUBLIC (decl) && !decl_binds_to_current_def_p (decl))
7848 : return false;
7849 :
7850 : /* Don't use section anchors for decls that will be placed in a
7851 : small data section. */
7852 : /* ??? Ideally, this check would be redundant with the SECTION_SMALL
7853 : one above. The problem is that we only use SECTION_SMALL for
7854 : sections that should be marked as small in the section directive. */
7855 0 : if (targetm.in_small_data_p (decl))
7856 : return false;
7857 :
7858 : /* Don't use section anchors for decls that won't fit inside a single
7859 : anchor range to reduce the amount of instructions required to refer
7860 : to the entire declaration. */
7861 0 : if (DECL_SIZE_UNIT (decl) == NULL_TREE
7862 0 : || !tree_fits_uhwi_p (DECL_SIZE_UNIT (decl))
7863 0 : || (tree_to_uhwi (DECL_SIZE_UNIT (decl))
7864 0 : >= (unsigned HOST_WIDE_INT) targetm.max_anchor_offset))
7865 0 : return false;
7866 :
7867 : }
7868 : return true;
7869 : }
7870 :
7871 : /* Return true when RESOLUTION indicate that symbol will be bound to the
7872 : definition provided by current .o file. */
7873 :
7874 : static bool
7875 302192832 : resolution_to_local_definition_p (enum ld_plugin_symbol_resolution resolution)
7876 : {
7877 302192832 : return (resolution == LDPR_PREVAILING_DEF
7878 302192832 : || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
7879 0 : || resolution == LDPR_PREVAILING_DEF_IRONLY);
7880 : }
7881 :
7882 : /* Return true when RESOLUTION indicate that symbol will be bound locally
7883 : within current executable or DSO. */
7884 :
7885 : static bool
7886 301161260 : resolution_local_p (enum ld_plugin_symbol_resolution resolution)
7887 : {
7888 301161260 : return (resolution == LDPR_PREVAILING_DEF
7889 301161260 : || resolution == LDPR_PREVAILING_DEF_IRONLY
7890 301161260 : || resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
7891 : || resolution == LDPR_PREEMPTED_REG
7892 301161260 : || resolution == LDPR_PREEMPTED_IR
7893 : || resolution == LDPR_RESOLVED_IR
7894 602322512 : || resolution == LDPR_RESOLVED_EXEC);
7895 : }
7896 :
7897 : /* COMMON_LOCAL_P is true means that the linker can guarantee that an
7898 : uninitialized common symbol in the executable will still be defined
7899 : (through COPY relocation) in the executable. */
7900 :
7901 : bool
7902 767096026 : default_binds_local_p_3 (const_tree exp, bool shlib, bool weak_dominate,
7903 : bool extern_protected_data, bool common_local_p)
7904 : {
7905 : /* A non-decl is an entry in the constant pool. */
7906 767096026 : if (!DECL_P (exp))
7907 : return true;
7908 :
7909 : /* Weakrefs may not bind locally, even though the weakref itself is always
7910 : static and therefore local. Similarly, the resolver for ifunc functions
7911 : might resolve to a non-local function.
7912 : FIXME: We can resolve the weakref case more carefully by looking at the
7913 : weakref alias. */
7914 763554194 : if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp))
7915 763554194 : || (!targetm.ifunc_ref_local_ok ()
7916 52723681 : && TREE_CODE (exp) == FUNCTION_DECL
7917 19384491 : && cgraph_node::get (exp)
7918 18642765 : && cgraph_node::get (exp)->ifunc_resolver))
7919 : return false;
7920 :
7921 : /* Static variables are always local. */
7922 763547646 : if (! TREE_PUBLIC (exp))
7923 : return true;
7924 :
7925 : /* With resolution file in hand, take look into resolutions.
7926 : We can't just return true for resolved_locally symbols,
7927 : because dynamic linking might overwrite symbols
7928 : in shared libraries. */
7929 613414518 : bool resolved_locally = false;
7930 :
7931 613414518 : bool uninited_common = (DECL_COMMON (exp)
7932 613414518 : && (DECL_INITIAL (exp) == NULL
7933 236430 : || (!in_lto_p
7934 236430 : && DECL_INITIAL (exp) == error_mark_node)));
7935 :
7936 : /* A non-external variable is defined locally only if it isn't
7937 : uninitialized COMMON variable or common_local_p is true. */
7938 613414518 : bool defined_locally = (!DECL_EXTERNAL (exp)
7939 613414518 : && (!uninited_common || common_local_p));
7940 613414518 : if (symtab_node *node = symtab_node::get (exp))
7941 : {
7942 598121444 : if (node->in_other_partition)
7943 3608 : defined_locally = true;
7944 598121444 : if (node->can_be_discarded_p ())
7945 : ;
7946 301686616 : else if (resolution_to_local_definition_p (node->resolution))
7947 : defined_locally = resolved_locally = true;
7948 301161260 : else if (resolution_local_p (node->resolution))
7949 613414518 : resolved_locally = true;
7950 : }
7951 613414518 : if (defined_locally && weak_dominate && !shlib)
7952 613414518 : resolved_locally = true;
7953 :
7954 : /* Undefined weak symbols are never defined locally. */
7955 613414518 : if (DECL_WEAK (exp) && !defined_locally)
7956 : return false;
7957 :
7958 : /* A symbol is local if the user has said explicitly that it will be,
7959 : or if we have a definition for the symbol. We cannot infer visibility
7960 : for undefined symbols. */
7961 613320637 : if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT
7962 10520729 : && (TREE_CODE (exp) == FUNCTION_DECL
7963 1025293 : || !extern_protected_data
7964 1025245 : || DECL_VISIBILITY (exp) != VISIBILITY_PROTECTED)
7965 623841324 : && (DECL_VISIBILITY_SPECIFIED (exp) || defined_locally))
7966 : return true;
7967 :
7968 : /* If PIC, then assume that any global name can be overridden by
7969 : symbols resolved from other modules. */
7970 608161316 : if (shlib)
7971 : return false;
7972 :
7973 : /* Variables defined outside this object might not be local. */
7974 514192866 : if (DECL_EXTERNAL (exp) && !resolved_locally)
7975 : return false;
7976 :
7977 : /* Non-dominant weak symbols are not defined locally. */
7978 310892942 : if (DECL_WEAK (exp) && !resolved_locally)
7979 : return false;
7980 :
7981 : /* Uninitialized COMMON variable may be unified with symbols
7982 : resolved from other modules. */
7983 310892942 : if (uninited_common && !resolved_locally)
7984 47 : return false;
7985 :
7986 : /* Otherwise we're left with initialized (or non-common) global data
7987 : which is of necessity defined locally. */
7988 : return true;
7989 : }
7990 :
7991 : /* Assume ELF-ish defaults, since that's pretty much the most liberal
7992 : wrt cross-module name binding. */
7993 :
7994 : bool
7995 0 : default_binds_local_p (const_tree exp)
7996 : {
7997 0 : return default_binds_local_p_3 (exp, flag_shlib != 0, true, false, false);
7998 : }
7999 :
8000 : /* Similar to default_binds_local_p, but common symbol may be local and
8001 : extern protected data is non-local. */
8002 :
8003 : bool
8004 0 : default_binds_local_p_2 (const_tree exp)
8005 : {
8006 0 : return default_binds_local_p_3 (exp, flag_shlib != 0, true, true,
8007 0 : !flag_pic);
8008 : }
8009 :
8010 : bool
8011 0 : default_binds_local_p_1 (const_tree exp, int shlib)
8012 : {
8013 0 : return default_binds_local_p_3 (exp, shlib != 0, false, false, false);
8014 : }
8015 :
8016 : /* Return true when references to DECL must bind to current definition in
8017 : final executable.
8018 :
8019 : The condition is usually equivalent to whether the function binds to the
8020 : current module (shared library or executable), that is to binds_local_p.
8021 : We use this fact to avoid need for another target hook and implement
8022 : the logic using binds_local_p and just special cases where
8023 : decl_binds_to_current_def_p is stronger than binds_local_p. In particular
8024 : the weak definitions (that can be overwritten at linktime by other
8025 : definition from different object file) and when resolution info is available
8026 : we simply use the knowledge passed to us by linker plugin. */
8027 : bool
8028 744679776 : decl_binds_to_current_def_p (const_tree decl)
8029 : {
8030 744679776 : gcc_assert (DECL_P (decl));
8031 744679776 : if (!targetm.binds_local_p (decl))
8032 : return false;
8033 456186252 : if (!TREE_PUBLIC (decl))
8034 : return true;
8035 :
8036 : /* When resolution is available, just use it. */
8037 310715619 : if (symtab_node *node = symtab_node::get (decl))
8038 : {
8039 310708132 : if (node->resolution != LDPR_UNKNOWN
8040 310708132 : && !node->can_be_discarded_p ())
8041 506216 : return resolution_to_local_definition_p (node->resolution);
8042 : }
8043 :
8044 : /* Otherwise we have to assume the worst for DECL_WEAK (hidden weaks
8045 : binds locally but still can be overwritten), DECL_COMMON (can be merged
8046 : with a non-common definition somewhere in the same module) or
8047 : DECL_EXTERNAL.
8048 : This rely on fact that binds_local_p behave as decl_replaceable_p
8049 : for all other declaration types. */
8050 310209403 : if (DECL_WEAK (decl))
8051 : return false;
8052 236456391 : if (DECL_COMDAT_GROUP (decl))
8053 : return false;
8054 236452648 : if (DECL_COMMON (decl)
8055 236452648 : && (DECL_INITIAL (decl) == NULL
8056 6 : || (!in_lto_p && DECL_INITIAL (decl) == error_mark_node)))
8057 : return false;
8058 235554523 : if (DECL_EXTERNAL (decl))
8059 2158625 : return false;
8060 : return true;
8061 : }
8062 :
8063 : /* A replaceable function or variable is one which may be replaced
8064 : at link-time with an entirely different definition, provided that the
8065 : replacement has the same type. For example, functions declared
8066 : with __attribute__((weak)) on most systems are replaceable.
8067 : If SEMANTIC_INTERPOSITION_P is false allow interposition only on
8068 : symbols explicitly declared weak.
8069 :
8070 : COMDAT functions are not replaceable, since all definitions of the
8071 : function must be equivalent. It is important that COMDAT functions
8072 : not be treated as replaceable so that use of C++ template
8073 : instantiations is not penalized. */
8074 :
8075 : bool
8076 239678382 : decl_replaceable_p (tree decl, bool semantic_interposition_p)
8077 : {
8078 239678382 : gcc_assert (DECL_P (decl));
8079 239678382 : if (!TREE_PUBLIC (decl) || DECL_COMDAT (decl))
8080 : return false;
8081 175737009 : if (!semantic_interposition_p
8082 175737009 : && !DECL_WEAK (decl))
8083 : return false;
8084 175548001 : return !decl_binds_to_current_def_p (decl);
8085 : }
8086 :
8087 : /* Default function to output code that will globalize a label. A
8088 : target must define GLOBAL_ASM_OP or provide its own function to
8089 : globalize a label. */
8090 : #ifdef GLOBAL_ASM_OP
8091 : void
8092 2203702 : default_globalize_label (FILE * stream, const char *name)
8093 : {
8094 2203702 : fputs (GLOBAL_ASM_OP, stream);
8095 2203702 : assemble_name (stream, name);
8096 2203702 : putc ('\n', stream);
8097 2203702 : }
8098 : #endif /* GLOBAL_ASM_OP */
8099 :
8100 : /* Default function to output code that will globalize a declaration. */
8101 : void
8102 2172376 : default_globalize_decl_name (FILE * stream, tree decl)
8103 : {
8104 2172376 : const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
8105 2172376 : targetm.asm_out.globalize_label (stream, name);
8106 2172376 : }
8107 :
8108 : /* Default function to output a label for unwind information. The
8109 : default is to do nothing. A target that needs nonlocal labels for
8110 : unwind information must provide its own function to do this. */
8111 : void
8112 52 : default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED,
8113 : tree decl ATTRIBUTE_UNUSED,
8114 : int for_eh ATTRIBUTE_UNUSED,
8115 : int empty ATTRIBUTE_UNUSED)
8116 : {
8117 52 : }
8118 :
8119 : /* Default function to output a label to divide up the exception table.
8120 : The default is to do nothing. A target that needs/wants to divide
8121 : up the table must provide it's own function to do this. */
8122 : void
8123 79923 : default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED)
8124 : {
8125 79923 : }
8126 :
8127 : /* This is how to output an internal numbered label where PREFIX is
8128 : the class of label and LABELNO is the number within the class. */
8129 :
8130 : void
8131 4622 : default_generate_internal_label (char *buf, const char *prefix,
8132 : unsigned long labelno)
8133 : {
8134 4622 : ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
8135 4622 : }
8136 :
8137 : /* This is how to output an internal numbered label where PREFIX is
8138 : the class of label and LABELNO is the number within the class. */
8139 :
8140 : void
8141 77129055 : default_internal_label (FILE *stream, const char *prefix,
8142 : unsigned long labelno)
8143 : {
8144 77129055 : char *const buf = (char *) alloca (40 + strlen (prefix));
8145 77129055 : ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno);
8146 77129055 : ASM_OUTPUT_INTERNAL_LABEL (stream, buf);
8147 77129055 : }
8148 :
8149 :
8150 : /* The default implementation of ASM_DECLARE_CONSTANT_NAME. */
8151 :
8152 : void
8153 1290843 : default_asm_declare_constant_name (FILE *file, const char *name,
8154 : const_tree exp ATTRIBUTE_UNUSED,
8155 : HOST_WIDE_INT size ATTRIBUTE_UNUSED)
8156 : {
8157 1290843 : assemble_label (file, name);
8158 1290843 : }
8159 :
8160 : /* This is the default behavior at the beginning of a file. It's
8161 : controlled by two other target-hook toggles. */
8162 : void
8163 286388 : default_file_start (void)
8164 : {
8165 286388 : if (targetm.asm_file_start_app_off
8166 0 : && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm))
8167 0 : fputs (ASM_APP_OFF, asm_out_file);
8168 :
8169 286388 : if (targetm.asm_file_start_file_directive)
8170 : {
8171 : /* LTO produced units have no meaningful main_input_filename. */
8172 286388 : if (in_lto_p)
8173 13844 : output_file_directive (asm_out_file, "<artificial>");
8174 : else
8175 272544 : output_file_directive (asm_out_file, main_input_filename);
8176 : }
8177 286388 : }
8178 :
8179 : /* This is a generic routine suitable for use as TARGET_ASM_FILE_END
8180 : which emits a special section directive used to indicate whether or
8181 : not this object file needs an executable stack. This is primarily
8182 : a GNU extension to ELF but could be used on other targets. */
8183 :
8184 : int trampolines_created;
8185 :
8186 : void
8187 256660 : file_end_indicate_exec_stack (void)
8188 : {
8189 256660 : unsigned int flags = SECTION_DEBUG;
8190 256660 : if (trampolines_created)
8191 243 : flags |= SECTION_CODE;
8192 :
8193 256660 : switch_to_section (get_section (".note.GNU-stack", flags, NULL));
8194 256660 : }
8195 :
8196 : /* Emit a special section directive to indicate that this object file
8197 : was compiled with -fsplit-stack. This is used to let the linker
8198 : detect calls between split-stack code and non-split-stack code, so
8199 : that it can modify the split-stack code to allocate a sufficiently
8200 : large stack. We emit another special section if there are any
8201 : functions in this file which have the no_split_stack attribute, to
8202 : prevent the linker from warning about being unable to convert the
8203 : functions if they call non-split-stack code. */
8204 :
8205 : void
8206 4711 : file_end_indicate_split_stack (void)
8207 : {
8208 4711 : if (flag_split_stack)
8209 : {
8210 4711 : switch_to_section (get_section (".note.GNU-split-stack", SECTION_DEBUG,
8211 : NULL));
8212 4711 : if (saw_no_split_stack)
8213 399 : switch_to_section (get_section (".note.GNU-no-split-stack",
8214 : SECTION_DEBUG, NULL));
8215 : }
8216 4711 : }
8217 :
8218 : /* Output DIRECTIVE (a C string) followed by a newline. This is used as
8219 : a get_unnamed_section callback. */
8220 :
8221 : void
8222 1853490 : output_section_asm_op (const char *directive)
8223 : {
8224 1853490 : fprintf (asm_out_file, "%s\n", directive);
8225 1853490 : }
8226 :
8227 : /* Emit assembly code to switch to section NEW_SECTION. Do nothing if
8228 : the current section is NEW_SECTION. */
8229 :
8230 : void
8231 102208121 : switch_to_section (section *new_section, tree decl)
8232 : {
8233 102208121 : bool retain_p;
8234 102208121 : if ((new_section->common.flags & SECTION_NAMED)
8235 74521534 : && decl != nullptr
8236 1867809 : && DECL_P (decl)
8237 104075930 : && ((retain_p = !!lookup_attribute ("retain",
8238 1867809 : DECL_ATTRIBUTES (decl)))
8239 1867809 : != !!(new_section->common.flags & SECTION_RETAIN)))
8240 : {
8241 : /* If the SECTION_RETAIN bit doesn't match, switch to a new
8242 : section. */
8243 24 : tree used_decl, no_used_decl;
8244 :
8245 24 : if (retain_p)
8246 : {
8247 12 : new_section->common.flags |= SECTION_RETAIN;
8248 12 : used_decl = decl;
8249 12 : no_used_decl = new_section->named.decl;
8250 : }
8251 : else
8252 : {
8253 12 : new_section->common.flags &= ~(SECTION_RETAIN
8254 : | SECTION_DECLARED);
8255 12 : used_decl = new_section->named.decl;
8256 12 : no_used_decl = decl;
8257 : }
8258 24 : if (no_used_decl != used_decl)
8259 : {
8260 24 : warning (OPT_Wattributes,
8261 : "%+qD without %<retain%> attribute and %qD with "
8262 : "%<retain%> attribute are placed in a section with "
8263 : "the same name", no_used_decl, used_decl);
8264 24 : inform (DECL_SOURCE_LOCATION (used_decl),
8265 : "%qD was declared here", used_decl);
8266 : }
8267 : }
8268 102208097 : else if (in_section == new_section)
8269 : return;
8270 :
8271 5541760 : in_section = new_section;
8272 :
8273 5541760 : switch (SECTION_STYLE (new_section))
8274 : {
8275 3688270 : case SECTION_NAMED:
8276 3688270 : targetm.asm_out.named_section (new_section->named.name,
8277 : new_section->named.common.flags,
8278 : new_section->named.decl);
8279 3688270 : break;
8280 :
8281 1853490 : case SECTION_UNNAMED:
8282 1853490 : new_section->unnamed.callback (new_section->unnamed.data);
8283 1853490 : break;
8284 :
8285 0 : case SECTION_NOSWITCH:
8286 0 : gcc_unreachable ();
8287 5541760 : break;
8288 : }
8289 :
8290 5541760 : new_section->common.flags |= SECTION_DECLARED;
8291 : }
8292 :
8293 : /* If block symbol SYMBOL has not yet been assigned an offset, place
8294 : it at the end of its block. */
8295 :
8296 : void
8297 0 : place_block_symbol (rtx symbol)
8298 : {
8299 0 : unsigned HOST_WIDE_INT size, mask, offset;
8300 0 : class constant_descriptor_rtx *desc;
8301 0 : unsigned int alignment;
8302 0 : struct object_block *block;
8303 0 : tree decl;
8304 :
8305 0 : gcc_assert (SYMBOL_REF_BLOCK (symbol));
8306 0 : if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0)
8307 : return;
8308 :
8309 : /* Work out the symbol's size and alignment. */
8310 0 : if (CONSTANT_POOL_ADDRESS_P (symbol))
8311 : {
8312 0 : desc = SYMBOL_REF_CONSTANT (symbol);
8313 0 : alignment = desc->align;
8314 0 : size = GET_MODE_SIZE (desc->mode);
8315 : }
8316 0 : else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
8317 : {
8318 0 : decl = SYMBOL_REF_DECL (symbol);
8319 0 : gcc_checking_assert (DECL_IN_CONSTANT_POOL (decl));
8320 0 : alignment = DECL_ALIGN (decl);
8321 0 : size = get_constant_size (DECL_INITIAL (decl));
8322 0 : if ((flag_sanitize & SANITIZE_ADDRESS)
8323 0 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8324 0 : && asan_protect_global (DECL_INITIAL (decl)))
8325 : {
8326 0 : size += asan_red_zone_size (size);
8327 0 : alignment = MAX (alignment,
8328 : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT);
8329 : }
8330 : }
8331 : else
8332 : {
8333 0 : struct symtab_node *snode;
8334 0 : decl = SYMBOL_REF_DECL (symbol);
8335 :
8336 0 : snode = symtab_node::get (decl);
8337 0 : if (snode->alias)
8338 : {
8339 0 : rtx target = DECL_RTL (snode->ultimate_alias_target ()->decl);
8340 :
8341 0 : gcc_assert (MEM_P (target)
8342 : && GET_CODE (XEXP (target, 0)) == SYMBOL_REF
8343 : && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (target, 0)));
8344 0 : target = XEXP (target, 0);
8345 0 : place_block_symbol (target);
8346 0 : SYMBOL_REF_BLOCK_OFFSET (symbol) = SYMBOL_REF_BLOCK_OFFSET (target);
8347 0 : return;
8348 : }
8349 0 : alignment = get_variable_align (decl);
8350 0 : size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
8351 0 : if ((flag_sanitize & SANITIZE_ADDRESS)
8352 0 : && asan_protect_global (decl))
8353 : {
8354 0 : size += asan_red_zone_size (size);
8355 0 : alignment = MAX (alignment,
8356 : ASAN_RED_ZONE_SIZE * BITS_PER_UNIT);
8357 : }
8358 : }
8359 :
8360 : /* Calculate the object's offset from the start of the block. */
8361 0 : block = SYMBOL_REF_BLOCK (symbol);
8362 0 : mask = alignment / BITS_PER_UNIT - 1;
8363 0 : offset = (block->size + mask) & ~mask;
8364 0 : SYMBOL_REF_BLOCK_OFFSET (symbol) = offset;
8365 :
8366 : /* Record the block's new alignment and size. */
8367 0 : block->alignment = MAX (block->alignment, alignment);
8368 0 : block->size = offset + size;
8369 :
8370 0 : vec_safe_push (block->objects, symbol);
8371 : }
8372 :
8373 : /* Return the anchor that should be used to address byte offset OFFSET
8374 : from the first object in BLOCK. MODEL is the TLS model used
8375 : to access it. */
8376 :
8377 : rtx
8378 0 : get_section_anchor (struct object_block *block, HOST_WIDE_INT offset,
8379 : enum tls_model model)
8380 : {
8381 0 : char label[100];
8382 0 : unsigned int begin, middle, end;
8383 0 : unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta;
8384 0 : rtx anchor;
8385 :
8386 : /* Work out the anchor's offset. Use an offset of 0 for the first
8387 : anchor so that we don't pessimize the case where we take the address
8388 : of a variable at the beginning of the block. This is particularly
8389 : useful when a block has only one variable assigned to it.
8390 :
8391 : We try to place anchors RANGE bytes apart, so there can then be
8392 : anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of
8393 : a ptr_mode offset. With some target settings, the lowest such
8394 : anchor might be out of range for the lowest ptr_mode offset;
8395 : likewise the highest anchor for the highest offset. Use anchors
8396 : at the extreme ends of the ptr_mode range in such cases.
8397 :
8398 : All arithmetic uses unsigned integers in order to avoid
8399 : signed overflow. */
8400 0 : max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset;
8401 0 : min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset;
8402 0 : range = max_offset - min_offset + 1;
8403 0 : if (range == 0)
8404 : offset = 0;
8405 : else
8406 : {
8407 0 : bias = HOST_WIDE_INT_1U << (GET_MODE_BITSIZE (ptr_mode) - 1);
8408 0 : if (offset < 0)
8409 : {
8410 0 : delta = -(unsigned HOST_WIDE_INT) offset + max_offset;
8411 0 : delta -= delta % range;
8412 0 : if (delta > bias)
8413 : delta = bias;
8414 0 : offset = (HOST_WIDE_INT) (-delta);
8415 : }
8416 : else
8417 : {
8418 0 : delta = (unsigned HOST_WIDE_INT) offset - min_offset;
8419 0 : delta -= delta % range;
8420 0 : if (delta > bias - 1)
8421 : delta = bias - 1;
8422 0 : offset = (HOST_WIDE_INT) delta;
8423 : }
8424 : }
8425 :
8426 : /* Do a binary search to see if there's already an anchor we can use.
8427 : Set BEGIN to the new anchor's index if not. */
8428 0 : begin = 0;
8429 0 : end = vec_safe_length (block->anchors);
8430 0 : while (begin != end)
8431 : {
8432 0 : middle = (end + begin) / 2;
8433 0 : anchor = (*block->anchors)[middle];
8434 0 : if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset)
8435 : end = middle;
8436 0 : else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset)
8437 0 : begin = middle + 1;
8438 0 : else if (SYMBOL_REF_TLS_MODEL (anchor) > model)
8439 : end = middle;
8440 0 : else if (SYMBOL_REF_TLS_MODEL (anchor) < model)
8441 0 : begin = middle + 1;
8442 : else
8443 : return anchor;
8444 : }
8445 :
8446 : /* Create a new anchor with a unique label. */
8447 0 : ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++);
8448 0 : anchor = create_block_symbol (ggc_strdup (label), block, offset);
8449 0 : SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR;
8450 0 : SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT;
8451 :
8452 : /* Insert it at index BEGIN. */
8453 0 : vec_safe_insert (block->anchors, begin, anchor);
8454 0 : return anchor;
8455 : }
8456 :
8457 : /* Output the objects in BLOCK. */
8458 :
8459 : static void
8460 0 : output_object_block (struct object_block *block)
8461 : {
8462 0 : class constant_descriptor_rtx *desc;
8463 0 : unsigned int i;
8464 0 : HOST_WIDE_INT offset;
8465 0 : tree decl;
8466 0 : rtx symbol;
8467 :
8468 0 : if (!block->objects)
8469 0 : return;
8470 :
8471 : /* Switch to the section and make sure that the first byte is
8472 : suitably aligned. */
8473 : /* Special case VTV comdat sections similar to assemble_variable. */
8474 0 : if (SECTION_STYLE (block->sect) == SECTION_NAMED
8475 0 : && block->sect->named.name
8476 0 : && (strcmp (block->sect->named.name, ".vtable_map_vars") == 0))
8477 0 : handle_vtv_comdat_section (block->sect, block->sect->named.decl);
8478 : else
8479 0 : switch_to_section (block->sect, SYMBOL_REF_DECL ((*block->objects)[0]));
8480 :
8481 0 : gcc_checking_assert (!(block->sect->common.flags & SECTION_MERGE));
8482 0 : assemble_align (block->alignment);
8483 :
8484 : /* Define the values of all anchors relative to the current section
8485 : position. */
8486 0 : FOR_EACH_VEC_SAFE_ELT (block->anchors, i, symbol)
8487 0 : targetm.asm_out.output_anchor (symbol);
8488 :
8489 : /* Output the objects themselves. */
8490 : offset = 0;
8491 0 : FOR_EACH_VEC_ELT (*block->objects, i, symbol)
8492 : {
8493 : /* Move to the object's offset, padding with zeros if necessary. */
8494 0 : assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset);
8495 0 : offset = SYMBOL_REF_BLOCK_OFFSET (symbol);
8496 0 : if (CONSTANT_POOL_ADDRESS_P (symbol))
8497 : {
8498 0 : desc = SYMBOL_REF_CONSTANT (symbol);
8499 : /* Pass 1 for align as we have already laid out everything in the block.
8500 : So aligning shouldn't be necessary. */
8501 0 : output_constant_pool_1 (desc, 1);
8502 0 : offset += GET_MODE_SIZE (desc->mode);
8503 : }
8504 0 : else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol))
8505 : {
8506 0 : HOST_WIDE_INT size;
8507 0 : decl = SYMBOL_REF_DECL (symbol);
8508 0 : assemble_constant_contents (DECL_INITIAL (decl), XSTR (symbol, 0),
8509 0 : DECL_ALIGN (decl), false);
8510 :
8511 0 : size = get_constant_size (DECL_INITIAL (decl));
8512 0 : offset += size;
8513 0 : if ((flag_sanitize & SANITIZE_ADDRESS)
8514 0 : && TREE_CODE (DECL_INITIAL (decl)) == STRING_CST
8515 0 : && asan_protect_global (DECL_INITIAL (decl)))
8516 : {
8517 0 : size = asan_red_zone_size (size);
8518 0 : assemble_zeros (size);
8519 0 : offset += size;
8520 : }
8521 : }
8522 : else
8523 : {
8524 0 : HOST_WIDE_INT size;
8525 0 : decl = SYMBOL_REF_DECL (symbol);
8526 0 : assemble_variable_contents (decl, XSTR (symbol, 0), false, false);
8527 0 : size = tree_to_uhwi (DECL_SIZE_UNIT (decl));
8528 0 : offset += size;
8529 0 : if ((flag_sanitize & SANITIZE_ADDRESS)
8530 0 : && asan_protect_global (decl))
8531 : {
8532 0 : size = asan_red_zone_size (size);
8533 0 : assemble_zeros (size);
8534 0 : offset += size;
8535 : }
8536 : }
8537 : }
8538 : }
8539 :
8540 : /* A callback for qsort to compare object_blocks. */
8541 :
8542 : static int
8543 0 : output_object_block_compare (const void *x, const void *y)
8544 : {
8545 0 : object_block *p1 = *(object_block * const*)x;
8546 0 : object_block *p2 = *(object_block * const*)y;
8547 :
8548 0 : if (p1->sect->common.flags & SECTION_NAMED
8549 0 : && !(p2->sect->common.flags & SECTION_NAMED))
8550 : return 1;
8551 :
8552 0 : if (!(p1->sect->common.flags & SECTION_NAMED)
8553 0 : && p2->sect->common.flags & SECTION_NAMED)
8554 : return -1;
8555 :
8556 0 : if (p1->sect->common.flags & SECTION_NAMED
8557 0 : && p2->sect->common.flags & SECTION_NAMED)
8558 0 : return strcmp (p1->sect->named.name, p2->sect->named.name);
8559 :
8560 0 : unsigned f1 = p1->sect->common.flags;
8561 0 : unsigned f2 = p2->sect->common.flags;
8562 0 : if (f1 == f2)
8563 : return 0;
8564 0 : return f1 < f2 ? -1 : 1;
8565 : }
8566 :
8567 : /* Output the definitions of all object_blocks. */
8568 :
8569 : void
8570 243525 : output_object_blocks (void)
8571 : {
8572 243525 : vec<object_block *, va_heap> v;
8573 243525 : v.create (object_block_htab->elements ());
8574 243525 : object_block *obj;
8575 243525 : hash_table<object_block_hasher>::iterator hi;
8576 :
8577 243525 : FOR_EACH_HASH_TABLE_ELEMENT (*object_block_htab, obj, object_block *, hi)
8578 0 : v.quick_push (obj);
8579 :
8580 : /* Sort them in order to output them in a deterministic manner,
8581 : otherwise we may get .rodata sections in different orders with
8582 : and without -g. */
8583 243525 : v.qsort (output_object_block_compare);
8584 243525 : unsigned i;
8585 243525 : FOR_EACH_VEC_ELT (v, i, obj)
8586 0 : output_object_block (obj);
8587 :
8588 243525 : v.release ();
8589 243525 : }
8590 :
8591 : /* This function provides a possible implementation of the
8592 : TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered
8593 : by -frecord-gcc-switches it creates a new mergeable, string section in the
8594 : assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which
8595 : contains the switches in ASCII format.
8596 :
8597 : FIXME: This code does not correctly handle double quote characters
8598 : that appear inside strings, (it strips them rather than preserving them).
8599 : FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL
8600 : characters - instead it treats them as sub-string separators. Since
8601 : we want to emit NUL strings terminators into the object file we have to use
8602 : ASM_OUTPUT_SKIP. */
8603 :
8604 : void
8605 0 : elf_record_gcc_switches (const char *options)
8606 : {
8607 0 : section *sec = get_section (targetm.asm_out.record_gcc_switches_section,
8608 : SECTION_DEBUG | SECTION_MERGE
8609 : | SECTION_STRINGS | (SECTION_ENTSIZE & 1), NULL);
8610 0 : switch_to_section (sec);
8611 0 : ASM_OUTPUT_ASCII (asm_out_file, options, strlen (options) + 1);
8612 0 : }
8613 :
8614 : /* Emit text to declare externally defined symbols. It is needed to
8615 : properly support non-default visibility. */
8616 : void
8617 1835045 : default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED,
8618 : tree decl,
8619 : const char *name ATTRIBUTE_UNUSED)
8620 : {
8621 : /* We output the name if and only if TREE_SYMBOL_REFERENCED is
8622 : set in order to avoid putting out names that are never really
8623 : used. Always output visibility specified in the source. */
8624 1835045 : if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl))
8625 1835045 : && (DECL_VISIBILITY_SPECIFIED (decl)
8626 1628433 : || targetm.binds_local_p (decl)))
8627 196232 : maybe_assemble_visibility (decl);
8628 1835045 : }
8629 :
8630 : /* The default hook for TARGET_ASM_OUTPUT_SOURCE_FILENAME. */
8631 :
8632 : void
8633 286388 : default_asm_output_source_filename (FILE *file, const char *name)
8634 : {
8635 : #ifdef ASM_OUTPUT_SOURCE_FILENAME
8636 : ASM_OUTPUT_SOURCE_FILENAME (file, name);
8637 : #else
8638 286388 : fprintf (file, "\t.file\t");
8639 286388 : output_quoted_string (file, name);
8640 286388 : putc ('\n', file);
8641 : #endif
8642 286388 : }
8643 :
8644 : /* Output a file name in the form wanted by System V. */
8645 :
8646 : void
8647 286388 : output_file_directive (FILE *asm_file, const char *input_name)
8648 : {
8649 286388 : int len;
8650 286388 : const char *na;
8651 :
8652 286388 : if (input_name == NULL)
8653 : input_name = "<stdin>";
8654 : else
8655 286388 : input_name = remap_debug_filename (input_name);
8656 :
8657 286388 : len = strlen (input_name);
8658 286388 : na = input_name + len;
8659 :
8660 : /* NA gets INPUT_NAME sans directory names. */
8661 4109856 : while (na > input_name)
8662 : {
8663 4077290 : if (IS_DIR_SEPARATOR (na[-1]))
8664 : break;
8665 3823468 : na--;
8666 : }
8667 :
8668 286388 : targetm.asm_out.output_source_filename (asm_file, na);
8669 286388 : }
8670 :
8671 : /* Create a DEBUG_EXPR_DECL / DEBUG_EXPR pair from RTL expression
8672 : EXP. */
8673 : rtx
8674 303103 : make_debug_expr_from_rtl (const_rtx exp)
8675 : {
8676 303103 : tree ddecl = make_node (DEBUG_EXPR_DECL), type;
8677 303103 : machine_mode mode = GET_MODE (exp);
8678 303103 : rtx dval;
8679 :
8680 303103 : DECL_ARTIFICIAL (ddecl) = 1;
8681 303103 : if (REG_P (exp) && REG_EXPR (exp))
8682 243484 : type = TREE_TYPE (REG_EXPR (exp));
8683 64362 : else if (MEM_P (exp) && MEM_EXPR (exp))
8684 4743 : type = TREE_TYPE (MEM_EXPR (exp));
8685 : else
8686 : type = NULL_TREE;
8687 248227 : if (type && TYPE_MODE (type) == mode)
8688 197718 : TREE_TYPE (ddecl) = type;
8689 : else
8690 105385 : TREE_TYPE (ddecl) = lang_hooks.types.type_for_mode (mode, 1);
8691 303103 : SET_DECL_MODE (ddecl, mode);
8692 303103 : dval = gen_rtx_DEBUG_EXPR (mode);
8693 303103 : DEBUG_EXPR_TREE_DECL (dval) = ddecl;
8694 303103 : SET_DECL_RTL (ddecl, dval);
8695 303103 : return dval;
8696 : }
8697 :
8698 : #ifdef ELF_ASCII_ESCAPES
8699 : /* Default ASM_OUTPUT_LIMITED_STRING for ELF targets. */
8700 :
8701 : void
8702 26764449 : default_elf_asm_output_limited_string (FILE *f, const char *s)
8703 : {
8704 26764449 : int escape;
8705 26764449 : unsigned char c;
8706 :
8707 26764449 : fputs (STRING_ASM_OP "\"", f);
8708 844580488 : while (*s != '\0')
8709 : {
8710 791051590 : c = *s;
8711 791051590 : escape = ELF_ASCII_ESCAPES[c];
8712 791051590 : switch (escape)
8713 : {
8714 790819128 : case 0:
8715 790819128 : putc (c, f);
8716 790819128 : break;
8717 118007 : case 1:
8718 118007 : putc ('\\', f);
8719 118007 : putc ('0'+((c>>6)&7), f);
8720 118007 : putc ('0'+((c>>3)&7), f);
8721 118007 : putc ('0'+(c&7), f);
8722 118007 : break;
8723 114455 : default:
8724 114455 : putc ('\\', f);
8725 114455 : putc (escape, f);
8726 114455 : break;
8727 : }
8728 791051590 : s++;
8729 : }
8730 26764449 : putc ('\"', f);
8731 26764449 : putc ('\n', f);
8732 26764449 : }
8733 :
8734 : /* Default ASM_OUTPUT_ASCII for ELF targets. */
8735 :
8736 : void
8737 37041047 : default_elf_asm_output_ascii (FILE *f, const char *s, unsigned int len)
8738 : {
8739 37041047 : const char *limit = s + len;
8740 37041047 : const char *last_null = NULL;
8741 37041047 : const char *last_base64 = s;
8742 37041047 : unsigned bytes_in_chunk = 0;
8743 37041047 : unsigned char c;
8744 37041047 : int escape;
8745 37041047 : bool prev_base64 = false;
8746 :
8747 305971754 : for (; s < limit; s++)
8748 : {
8749 268930707 : const char *p;
8750 :
8751 268930707 : if (bytes_in_chunk >= 60)
8752 : {
8753 3395819 : putc ('\"', f);
8754 3395819 : putc ('\n', f);
8755 3395819 : bytes_in_chunk = 0;
8756 : }
8757 :
8758 268930707 : if ((uintptr_t) s > (uintptr_t) last_null)
8759 : {
8760 1126231763 : for (p = s; p < limit && *p != '\0'; p++)
8761 1088865122 : continue;
8762 : last_null = p;
8763 : }
8764 : else
8765 : p = last_null;
8766 :
8767 : #if defined(BASE64_ASM_OP) \
8768 : && BITS_PER_UNIT == 8 \
8769 : && CHAR_BIT == 8 \
8770 : && 'A' == 65 \
8771 : && 'a' == 97 \
8772 : && '0' == 48 \
8773 : && '+' == 43 \
8774 : && '/' == 47 \
8775 : && '=' == 61
8776 268930707 : if (s >= last_base64)
8777 : {
8778 : unsigned cnt = 0;
8779 : unsigned char prev_c = ' ';
8780 : const char *t;
8781 1188978415 : for (t = s; t < limit && (t - s) < (long) ELF_STRING_LIMIT - 1; t++)
8782 : {
8783 1175545666 : if (t == p && t != s)
8784 : {
8785 25874349 : if (cnt <= ((unsigned) (t - s) + 1 + 2) / 3 * 4
8786 24890214 : && (!prev_base64 || (t - s) >= 16)
8787 24884817 : && ((t - s) > 1 || cnt <= 2))
8788 : {
8789 24789596 : last_base64 = p;
8790 24789596 : goto no_base64;
8791 : }
8792 : }
8793 1150756070 : c = *t;
8794 1150756070 : escape = ELF_ASCII_ESCAPES[c];
8795 1150756070 : switch (escape)
8796 : {
8797 1057854058 : case 0:
8798 1057854058 : ++cnt;
8799 1057854058 : break;
8800 87570901 : case 1:
8801 87570901 : if (c == 0)
8802 : {
8803 11186774 : if (prev_c == 0
8804 5777510 : && t + 1 < limit
8805 4911271 : && (t + 1 - s) < (long) ELF_STRING_LIMIT - 1)
8806 : break;
8807 6277521 : cnt += 2 + strlen (STRING_ASM_OP) + 1;
8808 : }
8809 : else
8810 76384127 : cnt += 4;
8811 : break;
8812 5331111 : default:
8813 5331111 : cnt += 2;
8814 5331111 : break;
8815 : }
8816 1150756070 : prev_c = c;
8817 : }
8818 13432749 : if (cnt > ((unsigned) (t - s) + 2) / 3 * 4 && (t - s) >= 3)
8819 : {
8820 1825104 : if (bytes_in_chunk > 0)
8821 : {
8822 580 : putc ('\"', f);
8823 580 : putc ('\n', f);
8824 580 : bytes_in_chunk = 0;
8825 : }
8826 :
8827 1825104 : unsigned char buf[(ELF_STRING_LIMIT + 2) / 3 * 4 + 3];
8828 1825104 : unsigned j = 0;
8829 1825104 : static const char base64_enc[] =
8830 : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
8831 : "0123456789+/";
8832 :
8833 1825104 : fputs (BASE64_ASM_OP "\"", f);
8834 47164981 : while (s < t)
8835 : {
8836 44835585 : unsigned char a = *s;
8837 44835585 : unsigned char b = 0, c = 0;
8838 44835585 : if (s < t - 1)
8839 44238195 : b = s[1];
8840 44835585 : if (s < t - 2)
8841 43514773 : c = s[2];
8842 44835585 : unsigned long v = ((((unsigned long) a) << 16)
8843 44835585 : | (((unsigned long) b) << 8)
8844 44835585 : | c);
8845 44835585 : buf[j++] = base64_enc[(v >> 18) & 63];
8846 44835585 : buf[j++] = base64_enc[(v >> 12) & 63];
8847 44835585 : buf[j++] = base64_enc[(v >> 6) & 63];
8848 44835585 : buf[j++] = base64_enc[v & 63];
8849 44835585 : if (s >= t - 2)
8850 : {
8851 1320812 : buf[j - 1] = '=';
8852 1320812 : if (s >= t - 1)
8853 597390 : buf[j - 2] = '=';
8854 : break;
8855 : }
8856 43514773 : s += 3;
8857 : }
8858 1825104 : memcpy (buf + j, "\"\n", 3);
8859 1825104 : fputs ((const char *) buf, f);
8860 1825104 : s = t - 1;
8861 1825104 : prev_base64 = true;
8862 1825104 : continue;
8863 1825104 : }
8864 : last_base64 = t;
8865 267105603 : no_base64:
8866 : prev_base64 = false;
8867 : }
8868 : #else
8869 : (void) last_base64;
8870 : (void) prev_base64;
8871 : #endif
8872 :
8873 267105603 : if (p < limit && (p - s) <= (long) ELF_STRING_LIMIT)
8874 : {
8875 26766261 : if (bytes_in_chunk > 0)
8876 : {
8877 217528 : putc ('\"', f);
8878 217528 : putc ('\n', f);
8879 217528 : bytes_in_chunk = 0;
8880 : }
8881 :
8882 26766261 : if (p == s && p + 1 < limit && p[1] == '\0')
8883 : {
8884 35752 : for (p = s + 2; p < limit && *p == '\0'; p++)
8885 33940 : continue;
8886 1812 : ASM_OUTPUT_SKIP (f, (unsigned HOST_WIDE_INT) (p - s));
8887 1812 : s = p - 1;
8888 : }
8889 : else
8890 : {
8891 26764449 : default_elf_asm_output_limited_string (f, s);
8892 26764449 : s = p;
8893 : }
8894 : }
8895 : else
8896 : {
8897 240339342 : if (bytes_in_chunk == 0)
8898 12511934 : fputs (ASCII_DATA_ASM_OP "\"", f);
8899 :
8900 240339342 : c = *s;
8901 240339342 : escape = ELF_ASCII_ESCAPES[c];
8902 240339342 : switch (escape)
8903 : {
8904 237563212 : case 0:
8905 237563212 : putc (c, f);
8906 237563212 : bytes_in_chunk++;
8907 237563212 : break;
8908 1073478 : case 1:
8909 1073478 : putc ('\\', f);
8910 1073478 : putc ('0'+((c>>6)&7), f);
8911 1073478 : putc ('0'+((c>>3)&7), f);
8912 1073478 : putc ('0'+(c&7), f);
8913 1073478 : bytes_in_chunk += 4;
8914 1073478 : break;
8915 1702652 : default:
8916 1702652 : putc ('\\', f);
8917 1702652 : putc (escape, f);
8918 1702652 : bytes_in_chunk += 2;
8919 1702652 : break;
8920 : }
8921 :
8922 : }
8923 : }
8924 :
8925 37041047 : if (bytes_in_chunk > 0)
8926 : {
8927 8898007 : putc ('\"', f);
8928 8898007 : putc ('\n', f);
8929 : }
8930 37041047 : }
8931 : #endif
8932 :
8933 : static GTY(()) section *elf_init_array_section;
8934 : static GTY(()) section *elf_fini_array_section;
8935 :
8936 : static section *
8937 26230 : get_elf_initfini_array_priority_section (int priority,
8938 : bool constructor_p)
8939 : {
8940 26230 : section *sec;
8941 26230 : if (priority != DEFAULT_INIT_PRIORITY)
8942 : {
8943 5319 : char buf[18];
8944 5319 : sprintf (buf, "%s.%.5u",
8945 : constructor_p ? ".init_array" : ".fini_array",
8946 : priority);
8947 5319 : sec = get_section (buf, SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
8948 : }
8949 : else
8950 : {
8951 20911 : if (constructor_p)
8952 : {
8953 20852 : if (elf_init_array_section == NULL)
8954 20023 : elf_init_array_section
8955 20023 : = get_section (".init_array",
8956 : SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
8957 20852 : sec = elf_init_array_section;
8958 : }
8959 : else
8960 : {
8961 59 : if (elf_fini_array_section == NULL)
8962 51 : elf_fini_array_section
8963 51 : = get_section (".fini_array",
8964 : SECTION_WRITE | SECTION_NOTYPE, NULL_TREE);
8965 59 : sec = elf_fini_array_section;
8966 : }
8967 : }
8968 26230 : return sec;
8969 : }
8970 :
8971 : /* Use .init_array section for constructors. */
8972 :
8973 : void
8974 24549 : default_elf_init_array_asm_out_constructor (rtx symbol, int priority)
8975 : {
8976 24549 : section *sec = get_elf_initfini_array_priority_section (priority,
8977 : true);
8978 24549 : assemble_addr_to_section (symbol, sec);
8979 24549 : }
8980 :
8981 : /* Use .fini_array section for destructors. */
8982 :
8983 : void
8984 1681 : default_elf_fini_array_asm_out_destructor (rtx symbol, int priority)
8985 : {
8986 1681 : section *sec = get_elf_initfini_array_priority_section (priority,
8987 : false);
8988 1681 : assemble_addr_to_section (symbol, sec);
8989 1681 : }
8990 :
8991 : /* Default TARGET_ASM_OUTPUT_IDENT hook.
8992 :
8993 : This is a bit of a cheat. The real default is a no-op, but this
8994 : hook is the default for all targets with a .ident directive. */
8995 :
8996 : void
8997 248475 : default_asm_output_ident_directive (const char *ident_str)
8998 : {
8999 248475 : const char *ident_asm_op = "\t.ident\t";
9000 :
9001 : /* If we are still in the front end, do not write out the string
9002 : to asm_out_file. Instead, add a fake top-level asm statement.
9003 : This allows the front ends to use this hook without actually
9004 : writing to asm_out_file, to handle #ident or Pragma Ident. */
9005 248475 : if (symtab->state == PARSING)
9006 : {
9007 27 : char *buf = ACONCAT ((ident_asm_op, "\"", ident_str, "\"\n", NULL));
9008 27 : symtab->finalize_toplevel_asm (build_string (strlen (buf), buf));
9009 : }
9010 : else
9011 248448 : fprintf (asm_out_file, "%s\"%s\"\n", ident_asm_op, ident_str);
9012 248475 : }
9013 :
9014 : /* Switch to a COMDAT section with COMDAT name of decl.
9015 :
9016 : FIXME: resolve_unique_section needs to deal better with
9017 : decls with both DECL_SECTION_NAME and DECL_ONE_ONLY. Once
9018 : that is fixed, this if-else statement can be replaced with
9019 : a single call to "switch_to_section (sect)". */
9020 :
9021 : void
9022 15 : switch_to_comdat_section (section *sect, tree decl)
9023 : {
9024 : #if defined (OBJECT_FORMAT_ELF)
9025 15 : targetm.asm_out.named_section (sect->named.name,
9026 15 : sect->named.common.flags
9027 : | SECTION_LINKONCE,
9028 : decl);
9029 15 : in_section = sect;
9030 : #else
9031 : /* Neither OBJECT_FORMAT_PE, nor OBJECT_FORMAT_COFF is set here.
9032 : Therefore the following check is used.
9033 : In case a the target is PE or COFF a comdat group section
9034 : is created, e.g. .vtable_map_vars$foo. The linker places
9035 : everything in .vtable_map_vars at the end.
9036 :
9037 : A fix could be made in
9038 : gcc/config/i386/winnt.cc: mingw_pe_unique_section. */
9039 : if (TARGET_PECOFF)
9040 : {
9041 : char *name;
9042 :
9043 : if (TREE_CODE (decl) == IDENTIFIER_NODE)
9044 : name = ACONCAT ((sect->named.name, "$",
9045 : IDENTIFIER_POINTER (decl), NULL));
9046 : else
9047 : name = ACONCAT ((sect->named.name, "$",
9048 : IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)),
9049 : NULL));
9050 :
9051 : targetm.asm_out.named_section (name,
9052 : sect->named.common.flags
9053 : | SECTION_LINKONCE,
9054 : decl);
9055 : in_section = sect;
9056 : }
9057 : else
9058 : switch_to_section (sect);
9059 : #endif
9060 15 : }
9061 :
9062 : /* This function ensures that vtable_map variables are not only
9063 : in the comdat section, but that each variable has its own unique
9064 : comdat name. Without this the variables end up in the same section
9065 : with a single comdat name. */
9066 :
9067 : static void
9068 3 : handle_vtv_comdat_section (section *sect, const_tree decl ATTRIBUTE_UNUSED)
9069 : {
9070 3 : switch_to_comdat_section(sect, DECL_NAME (decl));
9071 3 : }
9072 :
9073 : void
9074 272484 : varasm_cc_finalize ()
9075 : {
9076 272484 : first_global_object_name = nullptr;
9077 272484 : weak_global_object_name = nullptr;
9078 :
9079 272484 : const_labelno = 0;
9080 272484 : size_directive_output = 0;
9081 :
9082 272484 : last_assemble_variable_decl = NULL_TREE;
9083 272484 : first_function_block_is_cold = false;
9084 272484 : saw_no_split_stack = false;
9085 272484 : text_section = nullptr;
9086 272484 : data_section = nullptr;
9087 272484 : readonly_data_section = nullptr;
9088 272484 : sdata_section = nullptr;
9089 272484 : ctors_section = nullptr;
9090 272484 : dtors_section = nullptr;
9091 272484 : bss_section = nullptr;
9092 272484 : sbss_section = nullptr;
9093 272484 : tls_comm_section = nullptr;
9094 272484 : comm_section = nullptr;
9095 272484 : lcomm_section = nullptr;
9096 272484 : bss_noswitch_section = nullptr;
9097 272484 : exception_section = nullptr;
9098 272484 : eh_frame_section = nullptr;
9099 272484 : in_section = nullptr;
9100 272484 : in_cold_section_p = false;
9101 272484 : cold_function_name = NULL_TREE;
9102 272484 : unnamed_sections = nullptr;
9103 272484 : section_htab = nullptr;
9104 272484 : object_block_htab = nullptr;
9105 272484 : anchor_labelno = 0;
9106 272484 : shared_constant_pool = nullptr;
9107 272484 : pending_assemble_externals = NULL_TREE;
9108 272484 : pending_libcall_symbols = nullptr;
9109 :
9110 : #ifdef ASM_OUTPUT_EXTERNAL
9111 272484 : pending_assemble_externals_processed = false;
9112 294950 : delete pending_assemble_externals_set;
9113 272484 : pending_assemble_externals_set = nullptr;
9114 : #endif
9115 :
9116 272484 : weak_decls = NULL_TREE;
9117 272484 : initial_trampoline = nullptr;
9118 272484 : const_desc_htab = nullptr;
9119 272484 : weakref_targets = NULL_TREE;
9120 272484 : alias_pairs = nullptr;
9121 272484 : tm_clone_hash = nullptr;
9122 272484 : trampolines_created = 0;
9123 272484 : elf_init_array_section = nullptr;
9124 272484 : elf_fini_array_section = nullptr;
9125 272484 : }
9126 :
9127 : #include "gt-varasm.h"
|