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