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