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