]>
Commit | Line | Data |
---|---|---|
79e68feb | 1 | /* Output variables, constants and external declarations, for GNU compiler. |
06ceef4e | 2 | Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, |
71d59383 | 3 | 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 |
abb8b19a | 4 | Free Software Foundation, Inc. |
79e68feb | 5 | |
1322177d | 6 | This file is part of GCC. |
79e68feb | 7 | |
1322177d LB |
8 | GCC is free software; you can redistribute it and/or modify it under |
9 | the terms of the GNU General Public License as published by the Free | |
10 | Software Foundation; either version 2, or (at your option) any later | |
11 | version. | |
79e68feb | 12 | |
1322177d LB |
13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
79e68feb RS |
17 | |
18 | You should have received a copy of the GNU General Public License | |
1322177d | 19 | along with GCC; see the file COPYING. If not, write to the Free |
366ccddb KC |
20 | Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA |
21 | 02110-1301, USA. */ | |
79e68feb RS |
22 | |
23 | ||
24 | /* This file handles generation of all the assembler code | |
25 | *except* the instructions of a function. | |
26 | This includes declarations of variables and their initial values. | |
27 | ||
28 | We also output the assembler code for constants stored in memory | |
29 | and are responsible for combining constants with the same value. */ | |
30 | ||
e9a25f70 | 31 | #include "config.h" |
670ee920 | 32 | #include "system.h" |
4977bab6 ZW |
33 | #include "coretypes.h" |
34 | #include "tm.h" | |
79e68feb RS |
35 | #include "rtl.h" |
36 | #include "tree.h" | |
37 | #include "flags.h" | |
57632c51 | 38 | #include "function.h" |
79e68feb RS |
39 | #include "expr.h" |
40 | #include "hard-reg-set.h" | |
41 | #include "regs.h" | |
24b09b50 | 42 | #include "real.h" |
c7836bcd | 43 | #include "output.h" |
10f0ad3d | 44 | #include "toplev.h" |
bd7cf17e | 45 | #include "hashtab.h" |
3d6f7931 | 46 | #include "c-pragma.h" |
87ff9c8e | 47 | #include "ggc.h" |
ac79cd5a | 48 | #include "langhooks.h" |
aa388f29 | 49 | #include "tm_p.h" |
653e276c | 50 | #include "debug.h" |
7c262518 | 51 | #include "target.h" |
6de9cd9a | 52 | #include "tree-mudflap.h" |
1668aabc | 53 | #include "cgraph.h" |
750054a2 | 54 | #include "cfglayout.h" |
87c8b4be | 55 | #include "basic-block.h" |
79e68feb | 56 | |
440aabf8 NB |
57 | #ifdef XCOFF_DEBUGGING_INFO |
58 | #include "xcoffout.h" /* Needed for external data | |
59 | declarations for e.g. AIX 4.x. */ | |
60 | #endif | |
61 | ||
79e68feb | 62 | /* The (assembler) name of the first globally-visible object output. */ |
9881e3e5 MM |
63 | extern GTY(()) const char *first_global_object_name; |
64 | extern GTY(()) const char *weak_global_object_name; | |
65 | ||
3b304f5b ZW |
66 | const char *first_global_object_name; |
67 | const char *weak_global_object_name; | |
79e68feb | 68 | |
36edd3cc | 69 | struct addr_const; |
e2500fed | 70 | struct constant_descriptor_rtx; |
3234b52d | 71 | struct rtx_constant_pool; |
36edd3cc | 72 | |
e2500fed | 73 | struct varasm_status GTY(()) |
36edd3cc | 74 | { |
3234b52d RH |
75 | /* If we're using a per-function constant pool, this is it. */ |
76 | struct rtx_constant_pool *pool; | |
10b6a274 ZW |
77 | |
78 | /* Number of tree-constants deferred during the expansion of this | |
79 | function. */ | |
80 | unsigned int deferred_constants; | |
36edd3cc BS |
81 | }; |
82 | ||
10b6a274 | 83 | #define n_deferred_constants (cfun->varasm->deferred_constants) |
36edd3cc | 84 | |
79e68feb RS |
85 | /* Number for making the label on the next |
86 | constant that is stored in memory. */ | |
87 | ||
17211ab5 | 88 | static GTY(()) int const_labelno; |
79e68feb | 89 | |
dcc8e5e6 RS |
90 | /* Carry information from ASM_DECLARE_OBJECT_NAME |
91 | to ASM_FINISH_DECLARE_OBJECT. */ | |
92 | ||
93 | int size_directive_output; | |
94 | ||
cbed4565 RS |
95 | /* The last decl for which assemble_variable was called, |
96 | if it did ASM_DECLARE_OBJECT_NAME. | |
97 | If the last call to assemble_variable didn't do that, | |
98 | this holds 0. */ | |
99 | ||
100 | tree last_assemble_variable_decl; | |
101 | ||
87c8b4be CT |
102 | /* The following global variable indicates if the first basic block |
103 | in a function belongs to the cold partition or not. */ | |
750054a2 | 104 | |
87c8b4be | 105 | bool first_function_block_is_cold; |
750054a2 | 106 | |
389fdba0 RH |
107 | /* We give all constants their own alias set. Perhaps redundant with |
108 | MEM_READONLY_P, but pre-dates it. */ | |
a79e3a45 RK |
109 | |
110 | static HOST_WIDE_INT const_alias_set; | |
111 | ||
2e1eedd6 AJ |
112 | static const char *strip_reg_name (const char *); |
113 | static int contains_pointers_p (tree); | |
9be6533a RS |
114 | #ifdef ASM_OUTPUT_EXTERNAL |
115 | static bool incorporeal_function_p (tree); | |
116 | #endif | |
2e1eedd6 AJ |
117 | static void decode_addr_const (tree, struct addr_const *); |
118 | static hashval_t const_desc_hash (const void *); | |
119 | static int const_desc_eq (const void *, const void *); | |
120 | static hashval_t const_hash_1 (const tree); | |
121 | static int compare_constant (const tree, const tree); | |
122 | static tree copy_constant (tree); | |
123 | static void output_constant_def_contents (rtx); | |
b2218cc1 | 124 | static void output_addressed_constants (tree); |
2e1eedd6 AJ |
125 | static unsigned HOST_WIDE_INT array_size_for_constructor (tree); |
126 | static unsigned min_align (unsigned, unsigned); | |
127 | static void output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int); | |
128 | static void globalize_decl (tree); | |
129 | static void maybe_assemble_visibility (tree); | |
78a47b1d | 130 | #ifdef BSS_SECTION_ASM_OP |
0e05e8ea | 131 | #ifdef ASM_OUTPUT_BSS |
2e1eedd6 AJ |
132 | static void asm_output_bss (FILE *, tree, const char *, |
133 | unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT); | |
0e05e8ea JL |
134 | #endif |
135 | #ifdef ASM_OUTPUT_ALIGNED_BSS | |
2e1eedd6 AJ |
136 | static void asm_output_aligned_bss (FILE *, tree, const char *, |
137 | unsigned HOST_WIDE_INT, int) | |
138 | ATTRIBUTE_UNUSED; | |
0e05e8ea | 139 | #endif |
cab634f2 | 140 | #endif /* BSS_SECTION_ASM_OP */ |
2e1eedd6 | 141 | static void mark_weak (tree); |
79e68feb | 142 | \f |
d6b5193b RS |
143 | /* Well-known sections, each one associated with some sort of *_ASM_OP. */ |
144 | section *text_section; | |
145 | section *data_section; | |
146 | section *readonly_data_section; | |
147 | section *sdata_section; | |
148 | section *ctors_section; | |
149 | section *dtors_section; | |
150 | section *bss_section; | |
151 | section *sbss_section; | |
d6b5193b | 152 | |
434aeebb RS |
153 | /* Various forms of common section. All are guaranteed to be nonnull. */ |
154 | section *tls_comm_section; | |
155 | section *comm_section; | |
156 | section *lcomm_section; | |
157 | ||
158 | /* A SECTION_NOSWITCH section used for declaring global BSS variables. | |
159 | May be null. */ | |
160 | section *bss_noswitch_section; | |
161 | ||
0f67af1c RS |
162 | /* The section that holds the main exception table, when known. The section |
163 | is set either by the target's init_sections hook or by the first call to | |
164 | switch_to_exception_section. */ | |
d6b5193b RS |
165 | section *exception_section; |
166 | ||
0f67af1c RS |
167 | /* The section that holds the DWARF2 frame unwind information, when known. |
168 | The section is set either by the target's init_sections hook or by the | |
169 | first call to switch_to_eh_frame_section. */ | |
d6b5193b RS |
170 | section *eh_frame_section; |
171 | ||
172 | /* asm_out_file's current section. This is NULL if no section has yet | |
173 | been selected or if we lose track of what the current section is. */ | |
174 | section *in_section; | |
175 | ||
c543ca49 RS |
176 | /* True if code for the current function is currently being directed |
177 | at the cold section. */ | |
178 | bool in_cold_section_p; | |
d6b5193b RS |
179 | |
180 | /* A linked list of all the unnamed sections. */ | |
181 | static GTY(()) section *unnamed_sections; | |
79e68feb | 182 | |
0e9e1e0a | 183 | /* Return a nonzero value if DECL has a section attribute. */ |
a56e7c08 | 184 | #ifndef IN_NAMED_SECTION |
8a425a05 DE |
185 | #define IN_NAMED_SECTION(DECL) \ |
186 | ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \ | |
187 | && DECL_SECTION_NAME (DECL) != NULL_TREE) | |
a56e7c08 | 188 | #endif |
46f9491e | 189 | |
d6b5193b RS |
190 | /* Hash table of named sections. */ |
191 | static GTY((param_is (section))) htab_t section_htab; | |
8a425a05 | 192 | |
aacd3885 RS |
193 | /* A table of object_blocks, indexed by section. */ |
194 | static GTY((param_is (struct object_block))) htab_t object_block_htab; | |
195 | ||
196 | /* The next number to use for internal anchor labels. */ | |
197 | static GTY(()) int anchor_labelno; | |
198 | ||
d6b5193b | 199 | /* Helper routines for maintaining section_htab. */ |
715bdd29 | 200 | |
d6b5193b RS |
201 | static int |
202 | section_entry_eq (const void *p1, const void *p2) | |
715bdd29 | 203 | { |
d6b5193b RS |
204 | const section *old = p1; |
205 | const char *new = p2; | |
715bdd29 | 206 | |
d6b5193b RS |
207 | return strcmp (old->named.name, new) == 0; |
208 | } | |
715bdd29 | 209 | |
d6b5193b RS |
210 | static hashval_t |
211 | section_entry_hash (const void *p) | |
212 | { | |
213 | const section *old = p; | |
214 | return htab_hash_string (old->named.name); | |
215 | } | |
216 | ||
aacd3885 RS |
217 | /* Return a hash value for section SECT. */ |
218 | ||
219 | static hashval_t | |
220 | hash_section (section *sect) | |
221 | { | |
222 | if (sect->common.flags & SECTION_NAMED) | |
223 | return htab_hash_string (sect->named.name); | |
224 | return sect->common.flags; | |
225 | } | |
226 | ||
227 | /* Helper routines for maintaining object_block_htab. */ | |
228 | ||
229 | static int | |
230 | object_block_entry_eq (const void *p1, const void *p2) | |
231 | { | |
232 | const struct object_block *old = p1; | |
233 | const section *new = p2; | |
234 | ||
235 | return old->sect == new; | |
236 | } | |
237 | ||
238 | static hashval_t | |
239 | object_block_entry_hash (const void *p) | |
240 | { | |
241 | const struct object_block *old = p; | |
242 | return hash_section (old->sect); | |
243 | } | |
244 | ||
d6b5193b RS |
245 | /* Return a new unnamed section with the given fields. */ |
246 | ||
247 | section * | |
248 | get_unnamed_section (unsigned int flags, void (*callback) (const void *), | |
249 | const void *data) | |
250 | { | |
251 | section *sect; | |
252 | ||
253 | sect = ggc_alloc (sizeof (struct unnamed_section)); | |
434aeebb | 254 | sect->unnamed.common.flags = flags | SECTION_UNNAMED; |
d6b5193b RS |
255 | sect->unnamed.callback = callback; |
256 | sect->unnamed.data = data; | |
257 | sect->unnamed.next = unnamed_sections; | |
258 | ||
259 | unnamed_sections = sect; | |
260 | return sect; | |
261 | } | |
262 | ||
434aeebb RS |
263 | /* Return a SECTION_NOSWITCH section with the given fields. */ |
264 | ||
265 | static section * | |
266 | get_noswitch_section (unsigned int flags, noswitch_section_callback callback) | |
267 | { | |
268 | section *sect; | |
269 | ||
270 | sect = ggc_alloc (sizeof (struct unnamed_section)); | |
271 | sect->noswitch.common.flags = flags | SECTION_NOSWITCH; | |
272 | sect->noswitch.callback = callback; | |
273 | ||
274 | return sect; | |
275 | } | |
276 | ||
d6b5193b RS |
277 | /* Return the named section structure associated with NAME. Create |
278 | a new section with the given fields if no such structure exists. */ | |
279 | ||
280 | section * | |
281 | get_section (const char *name, unsigned int flags, tree decl) | |
282 | { | |
283 | section *sect, **slot; | |
284 | ||
285 | slot = (section **) | |
286 | htab_find_slot_with_hash (section_htab, name, | |
287 | htab_hash_string (name), INSERT); | |
0f67af1c | 288 | flags |= SECTION_NAMED; |
d6b5193b RS |
289 | if (*slot == NULL) |
290 | { | |
291 | sect = ggc_alloc (sizeof (struct named_section)); | |
0f67af1c | 292 | sect->named.common.flags = flags; |
d6b5193b RS |
293 | sect->named.name = ggc_strdup (name); |
294 | sect->named.decl = decl; | |
295 | *slot = sect; | |
296 | } | |
297 | else | |
298 | { | |
299 | sect = *slot; | |
0f67af1c | 300 | if ((sect->common.flags & ~SECTION_DECLARED) != flags |
d6b5193b RS |
301 | && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0) |
302 | { | |
303 | /* Sanity check user variables for flag changes. */ | |
304 | if (decl == 0) | |
305 | decl = sect->named.decl; | |
bf2f234e NS |
306 | gcc_assert (decl); |
307 | error ("%+D causes a section type conflict", decl); | |
d6b5193b RS |
308 | } |
309 | } | |
310 | return sect; | |
311 | } | |
79e68feb | 312 | |
aacd3885 RS |
313 | /* Return true if the current compilation mode benefits from having |
314 | objects grouped into blocks. */ | |
315 | ||
316 | static bool | |
317 | use_object_blocks_p (void) | |
318 | { | |
319 | return flag_section_anchors; | |
320 | } | |
321 | ||
322 | /* Return the object_block structure for section SECT. Create a new | |
434aeebb RS |
323 | structure if we haven't created one already. Return null if SECT |
324 | itself is null. */ | |
aacd3885 RS |
325 | |
326 | static struct object_block * | |
327 | get_block_for_section (section *sect) | |
328 | { | |
329 | struct object_block *block; | |
330 | void **slot; | |
331 | ||
434aeebb RS |
332 | if (sect == NULL) |
333 | return NULL; | |
334 | ||
aacd3885 RS |
335 | slot = htab_find_slot_with_hash (object_block_htab, sect, |
336 | hash_section (sect), INSERT); | |
337 | block = (struct object_block *) *slot; | |
338 | if (block == NULL) | |
339 | { | |
340 | block = (struct object_block *) | |
341 | ggc_alloc_cleared (sizeof (struct object_block)); | |
342 | block->sect = sect; | |
343 | *slot = block; | |
344 | } | |
345 | return block; | |
346 | } | |
347 | ||
348 | /* Create a symbol with label LABEL and place it at byte offset | |
349 | OFFSET in BLOCK. OFFSET can be negative if the symbol's offset | |
350 | is not yet known. LABEL must be a garbage-collected string. */ | |
351 | ||
352 | static rtx | |
353 | create_block_symbol (const char *label, struct object_block *block, | |
354 | HOST_WIDE_INT offset) | |
355 | { | |
356 | rtx symbol; | |
357 | unsigned int size; | |
358 | ||
359 | /* Create the extended SYMBOL_REF. */ | |
360 | size = RTX_HDR_SIZE + sizeof (struct block_symbol); | |
361 | symbol = ggc_alloc_zone (size, &rtl_zone); | |
362 | ||
363 | /* Initialize the normal SYMBOL_REF fields. */ | |
364 | memset (symbol, 0, size); | |
365 | PUT_CODE (symbol, SYMBOL_REF); | |
366 | PUT_MODE (symbol, Pmode); | |
367 | XSTR (symbol, 0) = label; | |
3fa9c136 | 368 | SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO; |
aacd3885 RS |
369 | |
370 | /* Initialize the block_symbol stuff. */ | |
371 | SYMBOL_REF_BLOCK (symbol) = block; | |
372 | SYMBOL_REF_BLOCK_OFFSET (symbol) = offset; | |
373 | ||
374 | return symbol; | |
375 | } | |
376 | ||
87c8b4be CT |
377 | static void |
378 | initialize_cold_section_name (void) | |
750054a2 | 379 | { |
c7466dee | 380 | const char *stripped_name; |
60ff97f4 RH |
381 | char *name, *buffer; |
382 | tree dsn; | |
9fb32434 | 383 | |
1ad435a5 CT |
384 | gcc_assert (cfun && current_function_decl); |
385 | if (cfun->unlikely_text_section_name) | |
386 | return; | |
387 | ||
60ff97f4 RH |
388 | dsn = DECL_SECTION_NAME (current_function_decl); |
389 | if (flag_function_sections && dsn) | |
750054a2 | 390 | { |
60ff97f4 RH |
391 | name = alloca (TREE_STRING_LENGTH (dsn) + 1); |
392 | memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1); | |
393 | ||
1ad435a5 | 394 | stripped_name = targetm.strip_name_encoding (name); |
60ff97f4 | 395 | |
1ad435a5 CT |
396 | buffer = ACONCAT ((stripped_name, "_unlikely", NULL)); |
397 | cfun->unlikely_text_section_name = ggc_strdup (buffer); | |
87c8b4be | 398 | } |
c7466dee | 399 | else |
1ad435a5 | 400 | cfun->unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME; |
87c8b4be CT |
401 | } |
402 | ||
87c8b4be CT |
403 | /* Tell assembler to switch to unlikely-to-be-executed text section. */ |
404 | ||
d6b5193b | 405 | section * |
87c8b4be CT |
406 | unlikely_text_section (void) |
407 | { | |
c7466dee CT |
408 | if (cfun) |
409 | { | |
410 | if (!cfun->unlikely_text_section_name) | |
411 | initialize_cold_section_name (); | |
9fb32434 | 412 | |
d6b5193b | 413 | return get_named_section (NULL, cfun->unlikely_text_section_name, 0); |
c7466dee CT |
414 | } |
415 | else | |
d6b5193b | 416 | return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0); |
274351ba | 417 | } |
6f2f3db7 | 418 | |
d6b5193b RS |
419 | /* When called within a function context, return true if the function |
420 | has been assigned a cold text section and if SECT is that section. | |
421 | When called outside a function context, return true if SECT is the | |
422 | default cold section. */ | |
a8c01a59 RL |
423 | |
424 | bool | |
d6b5193b | 425 | unlikely_text_section_p (section *sect) |
a8c01a59 | 426 | { |
d6b5193b | 427 | const char *name; |
a8c01a59 | 428 | |
d6b5193b RS |
429 | if (cfun) |
430 | name = cfun->unlikely_text_section_name; | |
c26fbbca | 431 | else |
d6b5193b | 432 | name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME; |
715bdd29 | 433 | |
d6b5193b RS |
434 | return (name |
435 | && sect | |
434aeebb | 436 | && SECTION_STYLE (sect) == SECTION_NAMED |
d6b5193b | 437 | && strcmp (name, sect->named.name) == 0); |
715bdd29 RH |
438 | } |
439 | ||
d6b5193b RS |
440 | /* Return a section with a particular name and with whatever SECTION_* |
441 | flags section_type_flags deems appropriate. The name of the section | |
442 | is taken from NAME if nonnull, otherwise it is taken from DECL's | |
443 | DECL_SECTION_NAME. DECL is the decl associated with the section | |
444 | (see the section comment for details) and RELOC is as for | |
445 | section_type_flags. */ | |
7c262518 | 446 | |
d6b5193b RS |
447 | section * |
448 | get_named_section (tree decl, const char *name, int reloc) | |
8a425a05 | 449 | { |
7c262518 RH |
450 | unsigned int flags; |
451 | ||
fbc848cc | 452 | gcc_assert (!decl || DECL_P (decl)); |
2ffe831c DE |
453 | if (name == NULL) |
454 | name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
455 | ||
245f1bfa | 456 | flags = targetm.section_type_flags (decl, name, reloc); |
715bdd29 | 457 | |
d6b5193b | 458 | return get_section (name, flags, decl); |
7c262518 | 459 | } |
e9a25f70 | 460 | |
7c262518 RH |
461 | /* If required, set DECL_SECTION_NAME to a unique name. */ |
462 | ||
89ce1c8f | 463 | void |
2e1eedd6 AJ |
464 | resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED, |
465 | int flag_function_or_data_sections) | |
7c262518 RH |
466 | { |
467 | if (DECL_SECTION_NAME (decl) == NULL_TREE | |
ae46c4e0 | 468 | && targetm.have_named_sections |
1b18fc2c | 469 | && (flag_function_or_data_sections |
ae46c4e0 | 470 | || DECL_ONE_ONLY (decl))) |
5fd9b178 | 471 | targetm.asm_out.unique_section (decl, reloc); |
8a425a05 | 472 | } |
4d1065ed | 473 | |
e5887033 DE |
474 | #ifdef BSS_SECTION_ASM_OP |
475 | ||
e5887033 DE |
476 | #ifdef ASM_OUTPUT_BSS |
477 | ||
478 | /* Utility function for ASM_OUTPUT_BSS for targets to use if | |
479 | they don't support alignments in .bss. | |
480 | ??? It is believed that this function will work in most cases so such | |
481 | support is localized here. */ | |
482 | ||
483 | static void | |
2e1eedd6 AJ |
484 | asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED, |
485 | const char *name, | |
486 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
487 | unsigned HOST_WIDE_INT rounded) | |
e5887033 | 488 | { |
5fd9b178 | 489 | targetm.asm_out.globalize_label (file, name); |
d6b5193b | 490 | switch_to_section (bss_section); |
91fddd7c DE |
491 | #ifdef ASM_DECLARE_OBJECT_NAME |
492 | last_assemble_variable_decl = decl; | |
493 | ASM_DECLARE_OBJECT_NAME (file, name, decl); | |
494 | #else | |
495 | /* Standard thing is just output label for the object. */ | |
e5887033 | 496 | ASM_OUTPUT_LABEL (file, name); |
91fddd7c | 497 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
95bfe95f | 498 | ASM_OUTPUT_SKIP (file, rounded ? rounded : 1); |
e5887033 DE |
499 | } |
500 | ||
501 | #endif | |
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 | |
2e1eedd6 AJ |
511 | asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED, |
512 | const char *name, unsigned HOST_WIDE_INT size, | |
513 | int align) | |
e5887033 | 514 | { |
d6b5193b | 515 | switch_to_section (bss_section); |
e5887033 | 516 | ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT)); |
91fddd7c DE |
517 | #ifdef ASM_DECLARE_OBJECT_NAME |
518 | last_assemble_variable_decl = decl; | |
519 | ASM_DECLARE_OBJECT_NAME (file, name, decl); | |
520 | #else | |
521 | /* Standard thing is just output label for the object. */ | |
e5887033 | 522 | ASM_OUTPUT_LABEL (file, name); |
91fddd7c | 523 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
f8bc3367 | 524 | ASM_OUTPUT_SKIP (file, size ? size : 1); |
e5887033 DE |
525 | } |
526 | ||
527 | #endif | |
528 | ||
529 | #endif /* BSS_SECTION_ASM_OP */ | |
530 | ||
c543ca49 RS |
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 | hot_function_section (tree decl) | |
537 | { | |
538 | if (decl != NULL_TREE | |
539 | && DECL_SECTION_NAME (decl) != NULL_TREE | |
540 | && targetm.have_named_sections) | |
541 | return get_named_section (decl, NULL, 0); | |
542 | else | |
543 | return text_section; | |
544 | } | |
545 | #endif | |
546 | ||
d6b5193b | 547 | /* Return the section for function DECL. |
4d1065ed | 548 | |
d6b5193b | 549 | If DECL is NULL_TREE, return the text section. We can be passed |
40aea05c | 550 | NULL_TREE under some circumstances by dbxout.c at least. */ |
4d1065ed | 551 | |
d6b5193b | 552 | section * |
2e1eedd6 | 553 | function_section (tree decl) |
4d1065ed | 554 | { |
c7466dee | 555 | int reloc = 0; |
083cad55 | 556 | |
87c8b4be | 557 | if (first_function_block_is_cold) |
c7466dee | 558 | reloc = 1; |
083cad55 | 559 | |
87c8b4be | 560 | #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS |
4c553323 JC |
561 | if (decl != NULL_TREE |
562 | && DECL_SECTION_NAME (decl) != NULL_TREE) | |
563 | return reloc ? unlikely_text_section () | |
564 | : get_named_section (decl, NULL, 0); | |
565 | else | |
566 | return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl)); | |
87c8b4be | 567 | #else |
4c553323 | 568 | return reloc ? unlikely_text_section () : hot_function_section (decl); |
87c8b4be CT |
569 | #endif |
570 | } | |
40aea05c | 571 | |
d6b5193b RS |
572 | section * |
573 | current_function_section (void) | |
87c8b4be | 574 | { |
f1a66265 | 575 | #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS |
4c553323 JC |
576 | if (current_function_decl != NULL_TREE |
577 | && DECL_SECTION_NAME (current_function_decl) != NULL_TREE) | |
578 | return in_cold_section_p ? unlikely_text_section () | |
579 | : get_named_section (current_function_decl, | |
580 | NULL, 0); | |
581 | else | |
582 | return targetm.asm_out.select_section (current_function_decl, | |
583 | in_cold_section_p, | |
584 | DECL_ALIGN (current_function_decl)); | |
f1a66265 | 585 | #else |
c543ca49 RS |
586 | return (in_cold_section_p |
587 | ? unlikely_text_section () | |
588 | : hot_function_section (current_function_decl)); | |
f1a66265 | 589 | #endif |
4d1065ed | 590 | } |
f9da1f35 | 591 | |
d6b5193b | 592 | /* Return the read-only data section associated with function DECL. */ |
ab5c8549 | 593 | |
d6b5193b | 594 | section * |
ab5c8549 JJ |
595 | default_function_rodata_section (tree decl) |
596 | { | |
597 | if (decl != NULL_TREE && DECL_SECTION_NAME (decl)) | |
598 | { | |
599 | const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
600 | ||
11176d2a JB |
601 | if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP) |
602 | { | |
603 | size_t len = strlen (name) + 3; | |
604 | char* rname = alloca (len); | |
083cad55 | 605 | |
11176d2a | 606 | strcpy (rname, ".rodata"); |
d6b5193b RS |
607 | strcat (rname, name + 5); |
608 | return get_section (rname, SECTION_LINKONCE, decl); | |
11176d2a | 609 | } |
ab5c8549 | 610 | /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */ |
11176d2a JB |
611 | else if (DECL_ONE_ONLY (decl) |
612 | && strncmp (name, ".gnu.linkonce.t.", 16) == 0) | |
ab5c8549 JJ |
613 | { |
614 | size_t len = strlen (name) + 1; | |
615 | char *rname = alloca (len); | |
616 | ||
617 | memcpy (rname, name, len); | |
618 | rname[14] = 'r'; | |
d6b5193b | 619 | return get_section (rname, SECTION_LINKONCE, decl); |
ab5c8549 JJ |
620 | } |
621 | /* For .text.foo we want to use .rodata.foo. */ | |
622 | else if (flag_function_sections && flag_data_sections | |
623 | && strncmp (name, ".text.", 6) == 0) | |
624 | { | |
625 | size_t len = strlen (name) + 1; | |
626 | char *rname = alloca (len + 2); | |
627 | ||
628 | memcpy (rname, ".rodata", 7); | |
629 | memcpy (rname + 7, name + 5, len - 5); | |
d6b5193b | 630 | return get_section (rname, 0, decl); |
ab5c8549 JJ |
631 | } |
632 | } | |
633 | ||
d6b5193b | 634 | return readonly_data_section; |
ab5c8549 JJ |
635 | } |
636 | ||
d6b5193b | 637 | /* Return the read-only data section associated with function DECL |
ab5c8549 JJ |
638 | for targets where that section should be always the single |
639 | readonly data section. */ | |
640 | ||
d6b5193b | 641 | section * |
ab5c8549 JJ |
642 | default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED) |
643 | { | |
d6b5193b | 644 | return readonly_data_section; |
ab5c8549 JJ |
645 | } |
646 | ||
d6b5193b | 647 | /* Return the section to use for string merging. */ |
201556f0 | 648 | |
d6b5193b | 649 | static section * |
2e1eedd6 AJ |
650 | mergeable_string_section (tree decl ATTRIBUTE_UNUSED, |
651 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED, | |
652 | unsigned int flags ATTRIBUTE_UNUSED) | |
201556f0 | 653 | { |
5d4856a0 | 654 | if (HAVE_GAS_SHF_MERGE && flag_merge_constants |
201556f0 JJ |
655 | && TREE_CODE (decl) == STRING_CST |
656 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
657 | && align <= 256 | |
658 | && TREE_STRING_LENGTH (decl) >= int_size_in_bytes (TREE_TYPE (decl))) | |
659 | { | |
660 | enum machine_mode mode; | |
661 | unsigned int modesize; | |
662 | const char *str; | |
663 | int i, j, len, unit; | |
664 | char name[30]; | |
665 | ||
666 | mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl))); | |
667 | modesize = GET_MODE_BITSIZE (mode); | |
668 | if (modesize >= 8 && modesize <= 256 | |
669 | && (modesize & (modesize - 1)) == 0) | |
670 | { | |
671 | if (align < modesize) | |
672 | align = modesize; | |
673 | ||
674 | str = TREE_STRING_POINTER (decl); | |
675 | len = TREE_STRING_LENGTH (decl); | |
676 | unit = GET_MODE_SIZE (mode); | |
677 | ||
678 | /* Check for embedded NUL characters. */ | |
679 | for (i = 0; i < len; i += unit) | |
680 | { | |
681 | for (j = 0; j < unit; j++) | |
c26fbbca | 682 | if (str[i + j] != '\0') |
201556f0 JJ |
683 | break; |
684 | if (j == unit) | |
685 | break; | |
686 | } | |
687 | if (i == len - unit) | |
688 | { | |
689 | sprintf (name, ".rodata.str%d.%d", modesize / 8, | |
690 | (int) (align / 8)); | |
691 | flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS; | |
d6b5193b | 692 | return get_section (name, flags, NULL); |
201556f0 JJ |
693 | } |
694 | } | |
695 | } | |
5d4856a0 | 696 | |
d6b5193b | 697 | return readonly_data_section; |
c26fbbca | 698 | } |
201556f0 | 699 | |
d6b5193b | 700 | /* Return the section to use for constant merging. */ |
201556f0 | 701 | |
d6b5193b | 702 | section * |
2e1eedd6 AJ |
703 | mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED, |
704 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED, | |
705 | unsigned int flags ATTRIBUTE_UNUSED) | |
201556f0 | 706 | { |
201556f0 JJ |
707 | unsigned int modesize = GET_MODE_BITSIZE (mode); |
708 | ||
5d4856a0 | 709 | if (HAVE_GAS_SHF_MERGE && flag_merge_constants |
201556f0 JJ |
710 | && mode != VOIDmode |
711 | && mode != BLKmode | |
712 | && modesize <= align | |
713 | && align >= 8 | |
714 | && align <= 256 | |
715 | && (align & (align - 1)) == 0) | |
716 | { | |
717 | char name[24]; | |
718 | ||
719 | sprintf (name, ".rodata.cst%d", (int) (align / 8)); | |
720 | flags |= (align / 8) | SECTION_MERGE; | |
d6b5193b | 721 | return get_section (name, flags, NULL); |
c26fbbca | 722 | } |
d6b5193b | 723 | return readonly_data_section; |
201556f0 | 724 | } |
79e68feb | 725 | \f |
b4ac57ab RS |
726 | /* Given NAME, a putative register name, discard any customary prefixes. */ |
727 | ||
87e11268 | 728 | static const char * |
2e1eedd6 | 729 | strip_reg_name (const char *name) |
b4ac57ab RS |
730 | { |
731 | #ifdef REGISTER_PREFIX | |
732 | if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX))) | |
733 | name += strlen (REGISTER_PREFIX); | |
734 | #endif | |
735 | if (name[0] == '%' || name[0] == '#') | |
736 | name++; | |
737 | return name; | |
738 | } | |
dcfedcd0 | 739 | \f |
0e6df31e GK |
740 | /* The user has asked for a DECL to have a particular name. Set (or |
741 | change) it in such a way that we don't prefix an underscore to | |
742 | it. */ | |
743 | void | |
744 | set_user_assembler_name (tree decl, const char *name) | |
745 | { | |
746 | char *starred = alloca (strlen (name) + 2); | |
747 | starred[0] = '*'; | |
748 | strcpy (starred + 1, name); | |
749 | change_decl_assembler_name (decl, get_identifier (starred)); | |
750 | SET_DECL_RTL (decl, NULL_RTX); | |
751 | } | |
752 | \f | |
79e68feb RS |
753 | /* Decode an `asm' spec for a declaration as a register name. |
754 | Return the register number, or -1 if nothing specified, | |
c09e6498 RS |
755 | or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized, |
756 | or -3 if ASMSPEC is `cc' and is not recognized, | |
757 | or -4 if ASMSPEC is `memory' and is not recognized. | |
dcfedcd0 RK |
758 | Accept an exact spelling or a decimal number. |
759 | Prefixes such as % are optional. */ | |
79e68feb RS |
760 | |
761 | int | |
2e1eedd6 | 762 | decode_reg_name (const char *asmspec) |
79e68feb | 763 | { |
30513cf6 | 764 | if (asmspec != 0) |
79e68feb RS |
765 | { |
766 | int i; | |
767 | ||
b4ac57ab RS |
768 | /* Get rid of confusing prefixes. */ |
769 | asmspec = strip_reg_name (asmspec); | |
46f9491e | 770 | |
fff9e713 MT |
771 | /* Allow a decimal number as a "register name". */ |
772 | for (i = strlen (asmspec) - 1; i >= 0; i--) | |
0df6c2c7 | 773 | if (! ISDIGIT (asmspec[i])) |
fff9e713 MT |
774 | break; |
775 | if (asmspec[0] != 0 && i < 0) | |
776 | { | |
777 | i = atoi (asmspec); | |
778 | if (i < FIRST_PSEUDO_REGISTER && i >= 0) | |
779 | return i; | |
780 | else | |
781 | return -2; | |
782 | } | |
783 | ||
79e68feb | 784 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
b4ac57ab RS |
785 | if (reg_names[i][0] |
786 | && ! strcmp (asmspec, strip_reg_name (reg_names[i]))) | |
79e68feb RS |
787 | return i; |
788 | ||
79e68feb RS |
789 | #ifdef ADDITIONAL_REGISTER_NAMES |
790 | { | |
83182544 | 791 | static const struct { const char *const name; const int number; } table[] |
79e68feb RS |
792 | = ADDITIONAL_REGISTER_NAMES; |
793 | ||
b6a1cbae | 794 | for (i = 0; i < (int) ARRAY_SIZE (table); i++) |
dd0ae678 R |
795 | if (table[i].name[0] |
796 | && ! strcmp (asmspec, table[i].name)) | |
79e68feb | 797 | return table[i].number; |
79e68feb RS |
798 | } |
799 | #endif /* ADDITIONAL_REGISTER_NAMES */ | |
800 | ||
c09e6498 RS |
801 | if (!strcmp (asmspec, "memory")) |
802 | return -4; | |
803 | ||
dcfedcd0 RK |
804 | if (!strcmp (asmspec, "cc")) |
805 | return -3; | |
806 | ||
79e68feb RS |
807 | return -2; |
808 | } | |
809 | ||
810 | return -1; | |
811 | } | |
812 | \f | |
434aeebb | 813 | /* Return true if DECL's initializer is suitable for a BSS section. */ |
aacd3885 RS |
814 | |
815 | static bool | |
434aeebb | 816 | bss_initializer_p (tree decl) |
aacd3885 | 817 | { |
434aeebb RS |
818 | return (DECL_INITIAL (decl) == NULL |
819 | || DECL_INITIAL (decl) == error_mark_node | |
820 | || (flag_zero_initialized_in_bss | |
821 | /* Leave constant zeroes in .rodata so they | |
822 | can be shared. */ | |
823 | && !TREE_READONLY (decl) | |
824 | && initializer_zerop (DECL_INITIAL (decl)))); | |
825 | } | |
826 | ||
827 | /* Return the section into which the given VAR_DECL or CONST_DECL | |
828 | should be placed. PREFER_NOSWITCH_P is true if a noswitch | |
829 | section should be used wherever possible. */ | |
830 | ||
831 | static section * | |
832 | get_variable_section (tree decl, bool prefer_noswitch_p) | |
833 | { | |
834 | int reloc; | |
835 | ||
836 | /* If the decl has been given an explicit section name, then it | |
837 | isn't common, and shouldn't be handled as such. */ | |
838 | if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL) | |
839 | { | |
840 | if (DECL_THREAD_LOCAL_P (decl)) | |
841 | return tls_comm_section; | |
842 | if (TREE_PUBLIC (decl) && bss_initializer_p (decl)) | |
843 | return comm_section; | |
844 | } | |
845 | ||
846 | if (DECL_INITIAL (decl) == error_mark_node) | |
847 | reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0; | |
848 | else if (DECL_INITIAL (decl)) | |
849 | reloc = compute_reloc_for_constant (DECL_INITIAL (decl)); | |
850 | else | |
851 | reloc = 0; | |
852 | ||
853 | resolve_unique_section (decl, reloc, flag_data_sections); | |
854 | if (IN_NAMED_SECTION (decl)) | |
855 | return get_named_section (decl, NULL, reloc); | |
856 | ||
857 | if (!DECL_THREAD_LOCAL_P (decl) | |
858 | && !(prefer_noswitch_p && targetm.have_switchable_bss_sections) | |
859 | && bss_initializer_p (decl)) | |
860 | { | |
861 | if (!TREE_PUBLIC (decl)) | |
862 | return lcomm_section; | |
863 | if (bss_noswitch_section) | |
864 | return bss_noswitch_section; | |
865 | } | |
866 | ||
867 | return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl)); | |
868 | } | |
869 | ||
870 | /* Return the block into which object_block DECL should be placed. */ | |
871 | ||
872 | static struct object_block * | |
873 | get_block_for_decl (tree decl) | |
874 | { | |
875 | section *sect; | |
aacd3885 RS |
876 | |
877 | if (TREE_CODE (decl) == VAR_DECL) | |
878 | { | |
879 | /* The object must be defined in this translation unit. */ | |
880 | if (DECL_EXTERNAL (decl)) | |
434aeebb | 881 | return NULL; |
aacd3885 RS |
882 | |
883 | /* There's no point using object blocks for something that is | |
884 | isolated by definition. */ | |
885 | if (DECL_ONE_ONLY (decl)) | |
434aeebb | 886 | return NULL; |
aacd3885 RS |
887 | } |
888 | ||
889 | /* We can only calculate block offsets if the decl has a known | |
890 | constant size. */ | |
891 | if (DECL_SIZE_UNIT (decl) == NULL) | |
434aeebb | 892 | return NULL; |
aacd3885 | 893 | if (!host_integerp (DECL_SIZE_UNIT (decl), 1)) |
434aeebb | 894 | return NULL; |
aacd3885 | 895 | |
434aeebb RS |
896 | /* Find out which section should contain DECL. We cannot put it into |
897 | an object block if it requires a standalone definition. */ | |
898 | sect = get_variable_section (decl, true); | |
899 | if (SECTION_STYLE (sect) == SECTION_NOSWITCH) | |
900 | return NULL; | |
aacd3885 | 901 | |
434aeebb | 902 | return get_block_for_section (sect); |
aacd3885 RS |
903 | } |
904 | ||
434aeebb | 905 | /* Make sure block symbol SYMBOL is in block BLOCK. */ |
aacd3885 RS |
906 | |
907 | static void | |
434aeebb | 908 | change_symbol_block (rtx symbol, struct object_block *block) |
aacd3885 | 909 | { |
434aeebb | 910 | if (block != SYMBOL_REF_BLOCK (symbol)) |
aacd3885 RS |
911 | { |
912 | gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0); | |
434aeebb | 913 | SYMBOL_REF_BLOCK (symbol) = block; |
aacd3885 RS |
914 | } |
915 | } | |
916 | ||
434aeebb | 917 | /* Return true if it is possible to put DECL in an object_block. */ |
aacd3885 | 918 | |
434aeebb RS |
919 | static bool |
920 | use_blocks_for_decl_p (tree decl) | |
aacd3885 | 921 | { |
434aeebb RS |
922 | /* Only data DECLs can be placed into object blocks. */ |
923 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL) | |
924 | return false; | |
aacd3885 | 925 | |
434aeebb RS |
926 | /* Detect decls created by dw2_force_const_mem. Such decls are |
927 | special because DECL_INITIAL doesn't specify the decl's true value. | |
928 | dw2_output_indirect_constants will instead call assemble_variable | |
929 | with dont_output_data set to 1 and then print the contents itself. */ | |
930 | if (DECL_INITIAL (decl) == decl) | |
931 | return false; | |
aacd3885 | 932 | |
434aeebb | 933 | return true; |
aacd3885 RS |
934 | } |
935 | ||
19e7881c MM |
936 | /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should |
937 | have static storage duration. In other words, it should not be an | |
938 | automatic variable, including PARM_DECLs. | |
939 | ||
940 | There is, however, one exception: this function handles variables | |
941 | explicitly placed in a particular register by the user. | |
942 | ||
79e68feb RS |
943 | This is never called for PARM_DECL nodes. */ |
944 | ||
945 | void | |
0e6df31e | 946 | make_decl_rtl (tree decl) |
79e68feb | 947 | { |
63ad61ed | 948 | const char *name = 0; |
ca695ac9 | 949 | int reg_number; |
abde42f7 | 950 | rtx x; |
ca695ac9 | 951 | |
19e7881c | 952 | /* Check that we are not being given an automatic variable. */ |
fbc848cc NS |
953 | gcc_assert (TREE_CODE (decl) != PARM_DECL |
954 | && TREE_CODE (decl) != RESULT_DECL); | |
955 | ||
9ea07fd0 | 956 | /* A weak alias has TREE_PUBLIC set but not the other bits. */ |
fbc848cc NS |
957 | gcc_assert (TREE_CODE (decl) != VAR_DECL |
958 | || TREE_STATIC (decl) | |
959 | || TREE_PUBLIC (decl) | |
960 | || DECL_EXTERNAL (decl) | |
961 | || DECL_REGISTER (decl)); | |
083cad55 | 962 | |
19e7881c | 963 | /* And that we were not given a type or a label. */ |
fbc848cc NS |
964 | gcc_assert (TREE_CODE (decl) != TYPE_DECL |
965 | && TREE_CODE (decl) != LABEL_DECL); | |
19e7881c | 966 | |
63ad61ed ZW |
967 | /* For a duplicate declaration, we can be called twice on the |
968 | same DECL node. Don't discard the RTL already made. */ | |
19e7881c | 969 | if (DECL_RTL_SET_P (decl)) |
79e68feb | 970 | { |
63ad61ed | 971 | /* If the old RTL had the wrong mode, fix the mode. */ |
aacd3885 RS |
972 | x = DECL_RTL (decl); |
973 | if (GET_MODE (x) != DECL_MODE (decl)) | |
974 | SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0)); | |
76095e2f | 975 | |
0e6df31e GK |
976 | if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)) |
977 | return; | |
978 | ||
b2e2d0cc EC |
979 | /* ??? Another way to do this would be to maintain a hashed |
980 | table of such critters. Instead of adding stuff to a DECL | |
981 | to give certain attributes to it, we could use an external | |
982 | hash map from DECL to set of attributes. */ | |
983 | ||
63ad61ed ZW |
984 | /* Let the target reassign the RTL if it wants. |
985 | This is necessary, for example, when one machine specific | |
986 | decl attribute overrides another. */ | |
245f1bfa | 987 | targetm.encode_section_info (decl, DECL_RTL (decl), false); |
6de9cd9a | 988 | |
3fa9c136 RS |
989 | /* If the symbol has a SYMBOL_REF_BLOCK field, update it based |
990 | on the new decl information. */ | |
aacd3885 RS |
991 | if (MEM_P (x) |
992 | && GET_CODE (XEXP (x, 0)) == SYMBOL_REF | |
3fa9c136 | 993 | && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0))) |
434aeebb | 994 | change_symbol_block (XEXP (x, 0), get_block_for_decl (decl)); |
aacd3885 | 995 | |
6de9cd9a DN |
996 | /* Make this function static known to the mudflap runtime. */ |
997 | if (flag_mudflap && TREE_CODE (decl) == VAR_DECL) | |
998 | mudflap_enqueue_decl (decl); | |
999 | ||
63ad61ed | 1000 | return; |
79e68feb RS |
1001 | } |
1002 | ||
26e0dcb3 | 1003 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
083cad55 | 1004 | |
11e3f4b6 AP |
1005 | if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL |
1006 | && DECL_REGISTER (decl)) | |
1007 | { | |
083cad55 | 1008 | error ("register name not specified for %q+D", decl); |
11e3f4b6 AP |
1009 | } |
1010 | else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)) | |
79e68feb | 1011 | { |
11e3f4b6 AP |
1012 | const char *asmspec = name+1; |
1013 | reg_number = decode_reg_name (asmspec); | |
79e68feb | 1014 | /* First detect errors in declaring global registers. */ |
63ad61ed | 1015 | if (reg_number == -1) |
dee15844 | 1016 | error ("register name not specified for %q+D", decl); |
63ad61ed | 1017 | else if (reg_number < 0) |
dee15844 | 1018 | error ("invalid register name for %q+D", decl); |
63ad61ed | 1019 | else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode) |
dee15844 JM |
1020 | error ("data type of %q+D isn%'t suitable for a register", |
1021 | decl); | |
63ad61ed | 1022 | else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl)))) |
dee15844 JM |
1023 | error ("register specified for %q+D isn%'t suitable for data type", |
1024 | decl); | |
79e68feb | 1025 | /* Now handle properly declared static register variables. */ |
63ad61ed | 1026 | else |
79e68feb RS |
1027 | { |
1028 | int nregs; | |
12266a61 | 1029 | |
e3406b2a | 1030 | if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl)) |
79e68feb RS |
1031 | { |
1032 | DECL_INITIAL (decl) = 0; | |
1033 | error ("global register variable has initial value"); | |
1034 | } | |
79e68feb | 1035 | if (TREE_THIS_VOLATILE (decl)) |
d35a40fc DE |
1036 | warning (OPT_Wvolatile_register_var, |
1037 | "optimization may eliminate reads and/or " | |
1038 | "writes to register variables"); | |
31e4b1c0 RK |
1039 | |
1040 | /* If the user specified one of the eliminables registers here, | |
1041 | e.g., FRAME_POINTER_REGNUM, we don't want to get this variable | |
3ada20ee RH |
1042 | confused with that register and be eliminated. This usage is |
1043 | somewhat suspect... */ | |
1044 | ||
1045 | SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number)); | |
1046 | ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number; | |
79e68feb RS |
1047 | REG_USERVAR_P (DECL_RTL (decl)) = 1; |
1048 | ||
6c418184 | 1049 | if (TREE_STATIC (decl)) |
79e68feb | 1050 | { |
ad800eb1 RK |
1051 | /* Make this register global, so not usable for anything |
1052 | else. */ | |
1cb36a98 | 1053 | #ifdef ASM_DECLARE_REGISTER_GLOBAL |
360ca054 | 1054 | name = IDENTIFIER_POINTER (DECL_NAME (decl)); |
1cb36a98 RH |
1055 | ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name); |
1056 | #endif | |
66fd46b6 | 1057 | nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)]; |
79e68feb | 1058 | while (nregs > 0) |
ad800eb1 | 1059 | globalize_reg (reg_number + --nregs); |
79e68feb | 1060 | } |
79e68feb | 1061 | |
63ad61ed ZW |
1062 | /* As a register variable, it has no section. */ |
1063 | return; | |
1064 | } | |
1065 | } | |
63ad61ed ZW |
1066 | /* Now handle ordinary static variables and functions (in memory). |
1067 | Also handle vars declared register invalidly. */ | |
30513cf6 AP |
1068 | else if (name[0] == '*') |
1069 | { | |
1070 | #ifdef REGISTER_PREFIX | |
1071 | if (strlen (REGISTER_PREFIX) != 0) | |
1072 | { | |
02676215 | 1073 | reg_number = decode_reg_name (name); |
30513cf6 | 1074 | if (reg_number >= 0 || reg_number == -3) |
dee15844 | 1075 | error ("register name given for non-register variable %q+D", decl); |
30513cf6 AP |
1076 | } |
1077 | #endif | |
1078 | } | |
63ad61ed ZW |
1079 | |
1080 | /* Specifying a section attribute on a variable forces it into a | |
2d76cb1a | 1081 | non-.bss section, and thus it cannot be common. */ |
63ad61ed ZW |
1082 | if (TREE_CODE (decl) == VAR_DECL |
1083 | && DECL_SECTION_NAME (decl) != NULL_TREE | |
1084 | && DECL_INITIAL (decl) == NULL_TREE | |
1085 | && DECL_COMMON (decl)) | |
1086 | DECL_COMMON (decl) = 0; | |
1087 | ||
5ff225fc MM |
1088 | /* Variables can't be both common and weak. */ |
1089 | if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl)) | |
1090 | DECL_COMMON (decl) = 0; | |
1091 | ||
aacd3885 | 1092 | if (use_object_blocks_p () && use_blocks_for_decl_p (decl)) |
434aeebb | 1093 | x = create_block_symbol (name, get_block_for_decl (decl), -1); |
aacd3885 RS |
1094 | else |
1095 | x = gen_rtx_SYMBOL_REF (Pmode, name); | |
52859c77 | 1096 | SYMBOL_REF_WEAK (x) = DECL_WEAK (decl); |
929e5e5b | 1097 | SET_SYMBOL_REF_DECL (x, decl); |
2e1eedd6 | 1098 | |
52859c77 | 1099 | x = gen_rtx_MEM (DECL_MODE (decl), x); |
63ad61ed | 1100 | if (TREE_CODE (decl) != FUNCTION_DECL) |
abde42f7 JH |
1101 | set_mem_attributes (x, decl, 1); |
1102 | SET_DECL_RTL (decl, x); | |
63ad61ed ZW |
1103 | |
1104 | /* Optionally set flags or add text to the name to record information | |
1105 | such as that it is a function name. | |
1106 | If the name is changed, the macro ASM_OUTPUT_LABELREF | |
1107 | will have to know how to strip this information. */ | |
245f1bfa | 1108 | targetm.encode_section_info (decl, DECL_RTL (decl), true); |
6de9cd9a DN |
1109 | |
1110 | /* Make this function static known to the mudflap runtime. */ | |
1111 | if (flag_mudflap && TREE_CODE (decl) == VAR_DECL) | |
1112 | mudflap_enqueue_decl (decl); | |
79e68feb | 1113 | } |
4724d87a RS |
1114 | |
1115 | /* Make the rtl for variable VAR be volatile. | |
1116 | Use this only for static variables. */ | |
1117 | ||
fcbaecc6 | 1118 | void |
2e1eedd6 | 1119 | make_var_volatile (tree var) |
4724d87a | 1120 | { |
fbc848cc | 1121 | gcc_assert (MEM_P (DECL_RTL (var))); |
4724d87a RS |
1122 | |
1123 | MEM_VOLATILE_P (DECL_RTL (var)) = 1; | |
1124 | } | |
79e68feb RS |
1125 | \f |
1126 | /* Output a string of literal assembler code | |
1127 | for an `asm' keyword used between functions. */ | |
1128 | ||
1129 | void | |
2e1eedd6 | 1130 | assemble_asm (tree string) |
79e68feb RS |
1131 | { |
1132 | app_enable (); | |
1133 | ||
1134 | if (TREE_CODE (string) == ADDR_EXPR) | |
1135 | string = TREE_OPERAND (string, 0); | |
1136 | ||
1137 | fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string)); | |
1138 | } | |
1139 | ||
2cc07db4 RH |
1140 | /* Record an element in the table of global destructors. SYMBOL is |
1141 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
1142 | between 0 and MAX_INIT_PRIORITY. */ | |
79e68feb RS |
1143 | |
1144 | void | |
bab208b4 AS |
1145 | default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED, |
1146 | int priority ATTRIBUTE_UNUSED) | |
79e68feb | 1147 | { |
93a27b7b | 1148 | #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO |
2cc07db4 RH |
1149 | /* Tell GNU LD that this is part of the static destructor set. |
1150 | This will work for any system that uses stabs, most usefully | |
1151 | aout systems. */ | |
93a27b7b ZW |
1152 | dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */); |
1153 | dbxout_stab_value_label (XSTR (symbol, 0)); | |
1154 | #else | |
1155 | sorry ("global destructors not supported on this target"); | |
1156 | #endif | |
2cc07db4 | 1157 | } |
47907859 | 1158 | |
2cc07db4 | 1159 | void |
2e1eedd6 | 1160 | default_named_section_asm_out_destructor (rtx symbol, int priority) |
2cc07db4 RH |
1161 | { |
1162 | const char *section = ".dtors"; | |
1163 | char buf[16]; | |
47907859 | 1164 | |
6d2f8887 | 1165 | /* ??? This only works reliably with the GNU linker. */ |
2cc07db4 | 1166 | if (priority != DEFAULT_INIT_PRIORITY) |
47907859 | 1167 | { |
47907859 RH |
1168 | sprintf (buf, ".dtors.%.5u", |
1169 | /* Invert the numbering so the linker puts us in the proper | |
1170 | order; constructors are run from right to left, and the | |
1171 | linker sorts in increasing order. */ | |
1172 | MAX_INIT_PRIORITY - priority); | |
2cc07db4 | 1173 | section = buf; |
47907859 RH |
1174 | } |
1175 | ||
d6b5193b | 1176 | switch_to_section (get_section (section, SECTION_WRITE, NULL)); |
715bdd29 | 1177 | assemble_align (POINTER_SIZE); |
c8af3574 | 1178 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); |
2cc07db4 RH |
1179 | } |
1180 | ||
1181 | #ifdef DTORS_SECTION_ASM_OP | |
2cc07db4 | 1182 | void |
2e1eedd6 AJ |
1183 | default_dtor_section_asm_out_destructor (rtx symbol, |
1184 | int priority ATTRIBUTE_UNUSED) | |
2cc07db4 | 1185 | { |
d6b5193b | 1186 | switch_to_section (dtors_section); |
c8af3574 RH |
1187 | assemble_align (POINTER_SIZE); |
1188 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); | |
2cc07db4 RH |
1189 | } |
1190 | #endif | |
1191 | ||
79e68feb RS |
1192 | /* Likewise for global constructors. */ |
1193 | ||
1194 | void | |
bab208b4 AS |
1195 | default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED, |
1196 | int priority ATTRIBUTE_UNUSED) | |
79e68feb | 1197 | { |
93a27b7b | 1198 | #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO |
2cc07db4 RH |
1199 | /* Tell GNU LD that this is part of the static destructor set. |
1200 | This will work for any system that uses stabs, most usefully | |
1201 | aout systems. */ | |
93a27b7b ZW |
1202 | dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */); |
1203 | dbxout_stab_value_label (XSTR (symbol, 0)); | |
1204 | #else | |
1205 | sorry ("global constructors not supported on this target"); | |
1206 | #endif | |
2cc07db4 | 1207 | } |
47907859 | 1208 | |
2cc07db4 | 1209 | void |
2e1eedd6 | 1210 | default_named_section_asm_out_constructor (rtx symbol, int priority) |
2cc07db4 RH |
1211 | { |
1212 | const char *section = ".ctors"; | |
1213 | char buf[16]; | |
47907859 | 1214 | |
6d2f8887 | 1215 | /* ??? This only works reliably with the GNU linker. */ |
2cc07db4 | 1216 | if (priority != DEFAULT_INIT_PRIORITY) |
47907859 | 1217 | { |
47907859 RH |
1218 | sprintf (buf, ".ctors.%.5u", |
1219 | /* Invert the numbering so the linker puts us in the proper | |
1220 | order; constructors are run from right to left, and the | |
1221 | linker sorts in increasing order. */ | |
1222 | MAX_INIT_PRIORITY - priority); | |
2cc07db4 | 1223 | section = buf; |
47907859 RH |
1224 | } |
1225 | ||
d6b5193b | 1226 | switch_to_section (get_section (section, SECTION_WRITE, NULL)); |
c8af3574 RH |
1227 | assemble_align (POINTER_SIZE); |
1228 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); | |
2cc07db4 RH |
1229 | } |
1230 | ||
1231 | #ifdef CTORS_SECTION_ASM_OP | |
2cc07db4 | 1232 | void |
2e1eedd6 AJ |
1233 | default_ctor_section_asm_out_constructor (rtx symbol, |
1234 | int priority ATTRIBUTE_UNUSED) | |
2cc07db4 | 1235 | { |
d6b5193b | 1236 | switch_to_section (ctors_section); |
c8af3574 RH |
1237 | assemble_align (POINTER_SIZE); |
1238 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); | |
2cc07db4 RH |
1239 | } |
1240 | #endif | |
79e68feb | 1241 | \f |
97adc6ed | 1242 | /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with |
0e9e1e0a | 1243 | a nonzero value if the constant pool should be output before the |
97adc6ed ILT |
1244 | start of the function, or a zero value if the pool should output |
1245 | after the end of the function. The default is to put it before the | |
1246 | start. */ | |
1247 | ||
1248 | #ifndef CONSTANT_POOL_BEFORE_FUNCTION | |
1249 | #define CONSTANT_POOL_BEFORE_FUNCTION 1 | |
1250 | #endif | |
1251 | ||
810db579 JH |
1252 | /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going |
1253 | to be output to assembler. | |
1254 | Set first_global_object_name and weak_global_object_name as appropriate. */ | |
1255 | ||
1256 | void | |
1257 | notice_global_symbol (tree decl) | |
1258 | { | |
8af11e80 JH |
1259 | const char **type = &first_global_object_name; |
1260 | ||
1261 | if (first_global_object_name | |
b5abd706 MS |
1262 | || !TREE_PUBLIC (decl) |
1263 | || DECL_EXTERNAL (decl) | |
8af11e80 JH |
1264 | || !DECL_NAME (decl) |
1265 | || (TREE_CODE (decl) != FUNCTION_DECL | |
1266 | && (TREE_CODE (decl) != VAR_DECL | |
1267 | || (DECL_COMMON (decl) | |
1268 | && (DECL_INITIAL (decl) == 0 | |
0f334035 | 1269 | || DECL_INITIAL (decl) == error_mark_node)))) |
3c0cb5de | 1270 | || !MEM_P (DECL_RTL (decl))) |
8af11e80 JH |
1271 | return; |
1272 | ||
321440fd | 1273 | /* We win when global object is found, but it is useful to know about weak |
8af11e80 JH |
1274 | symbol as well so we can produce nicer unique names. */ |
1275 | if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl)) | |
1276 | type = &weak_global_object_name; | |
1277 | ||
1278 | if (!*type) | |
810db579 JH |
1279 | { |
1280 | const char *p; | |
9881e3e5 | 1281 | const char *name; |
810db579 JH |
1282 | rtx decl_rtl = DECL_RTL (decl); |
1283 | ||
245f1bfa | 1284 | p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0)); |
9881e3e5 | 1285 | name = ggc_strdup (p); |
810db579 | 1286 | |
8af11e80 | 1287 | *type = name; |
810db579 JH |
1288 | } |
1289 | } | |
1290 | ||
79e68feb RS |
1291 | /* Output assembler code for the constant pool of a function and associated |
1292 | with defining the name of the function. DECL describes the function. | |
1293 | NAME is the function's name. For the constant pool, we use the current | |
1294 | constant pool data. */ | |
1295 | ||
1296 | void | |
2e1eedd6 | 1297 | assemble_start_function (tree decl, const char *fnname) |
79e68feb RS |
1298 | { |
1299 | int align; | |
c7466dee | 1300 | char tmp_label[100]; |
87c8b4be | 1301 | bool hot_label_written = false; |
79e68feb | 1302 | |
c7466dee | 1303 | cfun->unlikely_text_section_name = NULL; |
083cad55 | 1304 | |
87c8b4be | 1305 | first_function_block_is_cold = false; |
c7466dee CT |
1306 | if (flag_reorder_blocks_and_partition) |
1307 | { | |
affb0e06 | 1308 | ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno); |
c7466dee | 1309 | cfun->hot_section_label = ggc_strdup (tmp_label); |
affb0e06 | 1310 | ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno); |
c7466dee | 1311 | cfun->cold_section_label = ggc_strdup (tmp_label); |
affb0e06 | 1312 | ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno); |
c7466dee | 1313 | cfun->hot_section_end_label = ggc_strdup (tmp_label); |
affb0e06 | 1314 | ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno); |
c7466dee CT |
1315 | cfun->cold_section_end_label = ggc_strdup (tmp_label); |
1316 | const_labelno++; | |
1317 | } | |
1318 | else | |
1319 | { | |
1320 | cfun->hot_section_label = NULL; | |
1321 | cfun->cold_section_label = NULL; | |
1322 | cfun->hot_section_end_label = NULL; | |
1323 | cfun->cold_section_end_label = NULL; | |
1324 | } | |
87c8b4be | 1325 | |
79e68feb RS |
1326 | /* The following code does not need preprocessing in the assembler. */ |
1327 | ||
1328 | app_disable (); | |
1329 | ||
97adc6ed ILT |
1330 | if (CONSTANT_POOL_BEFORE_FUNCTION) |
1331 | output_constant_pool (fnname, decl); | |
79e68feb | 1332 | |
1ad435a5 CT |
1333 | resolve_unique_section (decl, 0, flag_function_sections); |
1334 | ||
87c8b4be CT |
1335 | /* Make sure the not and cold text (code) sections are properly |
1336 | aligned. This is necessary here in the case where the function | |
1337 | has both hot and cold sections, because we don't want to re-set | |
1338 | the alignment when the section switch happens mid-function. */ | |
c295317d CT |
1339 | |
1340 | if (flag_reorder_blocks_and_partition) | |
1341 | { | |
c543ca49 | 1342 | switch_to_section (unlikely_text_section ()); |
c295317d | 1343 | assemble_align (FUNCTION_BOUNDARY); |
c7466dee | 1344 | ASM_OUTPUT_LABEL (asm_out_file, cfun->cold_section_label); |
e4598783 SB |
1345 | |
1346 | /* When the function starts with a cold section, we need to explicitly | |
1347 | align the hot section and write out the hot section label. | |
1348 | But if the current function is a thunk, we do not have a CFG. */ | |
1349 | if (!current_function_is_thunk | |
1350 | && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION) | |
87c8b4be | 1351 | { |
d6b5193b | 1352 | switch_to_section (text_section); |
87c8b4be | 1353 | assemble_align (FUNCTION_BOUNDARY); |
c7466dee | 1354 | ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_label); |
87c8b4be CT |
1355 | hot_label_written = true; |
1356 | first_function_block_is_cold = true; | |
1357 | } | |
1358 | } | |
1359 | else if (DECL_SECTION_NAME (decl)) | |
1360 | { | |
1361 | /* Calls to function_section rely on first_function_block_is_cold | |
1362 | being accurate. The first block may be cold even if we aren't | |
1363 | doing partitioning, if the entire function was decided by | |
1364 | choose_function_section (predict.c) to be cold. */ | |
1365 | ||
87c8b4be CT |
1366 | initialize_cold_section_name (); |
1367 | ||
083cad55 | 1368 | if (cfun->unlikely_text_section_name |
60ff97f4 RH |
1369 | && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)), |
1370 | cfun->unlikely_text_section_name) == 0) | |
87c8b4be | 1371 | first_function_block_is_cold = true; |
c295317d CT |
1372 | } |
1373 | ||
c543ca49 | 1374 | in_cold_section_p = first_function_block_is_cold; |
87c8b4be CT |
1375 | |
1376 | /* Switch to the correct text section for the start of the function. */ | |
1377 | ||
d6b5193b | 1378 | switch_to_section (function_section (decl)); |
083cad55 | 1379 | if (flag_reorder_blocks_and_partition |
b3b51ded | 1380 | && !hot_label_written) |
c7466dee | 1381 | ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_label); |
79e68feb RS |
1382 | |
1383 | /* Tell assembler to move to target machine's alignment for functions. */ | |
1384 | align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT); | |
f963b5d9 RS |
1385 | if (align < force_align_functions_log) |
1386 | align = force_align_functions_log; | |
79e68feb | 1387 | if (align > 0) |
91ea4f8d KG |
1388 | { |
1389 | ASM_OUTPUT_ALIGN (asm_out_file, align); | |
1390 | } | |
79e68feb | 1391 | |
efa3896a GK |
1392 | /* Handle a user-specified function alignment. |
1393 | Note that we still need to align to FUNCTION_BOUNDARY, as above, | |
1394 | because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */ | |
194734e9 JH |
1395 | if (align_functions_log > align |
1396 | && cfun->function_frequency != FUNCTION_FREQUENCY_UNLIKELY_EXECUTED) | |
efa3896a GK |
1397 | { |
1398 | #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN | |
46f9491e | 1399 | ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file, |
c26fbbca | 1400 | align_functions_log, align_functions - 1); |
efa3896a GK |
1401 | #else |
1402 | ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log); | |
1403 | #endif | |
1404 | } | |
1405 | ||
79e68feb RS |
1406 | #ifdef ASM_OUTPUT_FUNCTION_PREFIX |
1407 | ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname); | |
1408 | #endif | |
1409 | ||
653e276c | 1410 | (*debug_hooks->begin_function) (decl); |
79e68feb RS |
1411 | |
1412 | /* Make function name accessible from other files, if appropriate. */ | |
1413 | ||
1414 | if (TREE_PUBLIC (decl)) | |
1415 | { | |
810db579 | 1416 | notice_global_symbol (decl); |
06bb02f7 | 1417 | |
19c5b1cf | 1418 | globalize_decl (decl); |
b14707c3 RH |
1419 | |
1420 | maybe_assemble_visibility (decl); | |
79e68feb RS |
1421 | } |
1422 | ||
8e3e233b DP |
1423 | if (DECL_PRESERVE_P (decl)) |
1424 | targetm.asm_out.mark_decl_preserved (fnname); | |
1425 | ||
6614fd40 | 1426 | /* Do any machine/system dependent processing of the function name. */ |
8bd16853 | 1427 | #ifdef ASM_DECLARE_FUNCTION_NAME |
b93a436e | 1428 | ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl); |
8bd16853 | 1429 | #else |
b93a436e JL |
1430 | /* Standard thing is just output label for the function. */ |
1431 | ASM_OUTPUT_LABEL (asm_out_file, fnname); | |
79e68feb RS |
1432 | #endif /* ASM_DECLARE_FUNCTION_NAME */ |
1433 | } | |
1434 | ||
1435 | /* Output assembler code associated with defining the size of the | |
1436 | function. DECL describes the function. NAME is the function's name. */ | |
1437 | ||
1438 | void | |
2e1eedd6 | 1439 | assemble_end_function (tree decl, const char *fnname) |
79e68feb RS |
1440 | { |
1441 | #ifdef ASM_DECLARE_FUNCTION_SIZE | |
43f237b4 EB |
1442 | /* We could have switched section in the middle of the function. */ |
1443 | if (flag_reorder_blocks_and_partition) | |
d6b5193b | 1444 | switch_to_section (function_section (decl)); |
79e68feb RS |
1445 | ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl); |
1446 | #endif | |
97adc6ed | 1447 | if (! CONSTANT_POOL_BEFORE_FUNCTION) |
83488369 RK |
1448 | { |
1449 | output_constant_pool (fnname, decl); | |
d6b5193b | 1450 | switch_to_section (function_section (decl)); /* need to switch back */ |
83488369 | 1451 | } |
87c8b4be CT |
1452 | /* Output labels for end of hot/cold text sections (to be used by |
1453 | debug info.) */ | |
b3b51ded CT |
1454 | if (flag_reorder_blocks_and_partition) |
1455 | { | |
d6b5193b | 1456 | section *save_text_section; |
c7466dee | 1457 | |
b3b51ded | 1458 | save_text_section = in_section; |
c543ca49 | 1459 | switch_to_section (unlikely_text_section ()); |
c7466dee | 1460 | ASM_OUTPUT_LABEL (asm_out_file, cfun->cold_section_end_label); |
1ad435a5 | 1461 | if (first_function_block_is_cold) |
d6b5193b | 1462 | switch_to_section (text_section); |
1ad435a5 | 1463 | else |
d6b5193b | 1464 | switch_to_section (function_section (decl)); |
c7466dee | 1465 | ASM_OUTPUT_LABEL (asm_out_file, cfun->hot_section_end_label); |
d6b5193b | 1466 | switch_to_section (save_text_section); |
b3b51ded | 1467 | } |
79e68feb RS |
1468 | } |
1469 | \f | |
1470 | /* Assemble code to leave SIZE bytes of zeros. */ | |
1471 | ||
1472 | void | |
2e1eedd6 | 1473 | assemble_zeros (unsigned HOST_WIDE_INT size) |
79e68feb | 1474 | { |
3c350eb3 CB |
1475 | /* Do no output if -fsyntax-only. */ |
1476 | if (flag_syntax_only) | |
1477 | return; | |
1478 | ||
79e68feb RS |
1479 | #ifdef ASM_NO_SKIP_IN_TEXT |
1480 | /* The `space' pseudo in the text section outputs nop insns rather than 0s, | |
1481 | so we must output 0s explicitly in the text section. */ | |
d6b5193b | 1482 | if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0) |
79e68feb | 1483 | { |
58e15542 | 1484 | unsigned HOST_WIDE_INT i; |
c8af3574 RH |
1485 | for (i = 0; i < size; i++) |
1486 | assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1); | |
79e68feb RS |
1487 | } |
1488 | else | |
1489 | #endif | |
41fe4d9e | 1490 | if (size > 0) |
b93a436e | 1491 | ASM_OUTPUT_SKIP (asm_out_file, size); |
79e68feb RS |
1492 | } |
1493 | ||
a785e67e RS |
1494 | /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */ |
1495 | ||
1496 | void | |
2e1eedd6 | 1497 | assemble_align (int align) |
a785e67e RS |
1498 | { |
1499 | if (align > BITS_PER_UNIT) | |
91ea4f8d KG |
1500 | { |
1501 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
1502 | } | |
a785e67e RS |
1503 | } |
1504 | ||
79e68feb RS |
1505 | /* Assemble a string constant with the specified C string as contents. */ |
1506 | ||
1507 | void | |
2e1eedd6 | 1508 | assemble_string (const char *p, int size) |
79e68feb | 1509 | { |
79e68feb RS |
1510 | int pos = 0; |
1511 | int maximum = 2000; | |
1512 | ||
1513 | /* If the string is very long, split it up. */ | |
1514 | ||
1515 | while (pos < size) | |
1516 | { | |
1517 | int thissize = size - pos; | |
1518 | if (thissize > maximum) | |
1519 | thissize = maximum; | |
1520 | ||
b93a436e | 1521 | ASM_OUTPUT_ASCII (asm_out_file, p, thissize); |
79e68feb RS |
1522 | |
1523 | pos += thissize; | |
1524 | p += thissize; | |
1525 | } | |
1526 | } | |
69249c1b | 1527 | |
79e68feb | 1528 | \f |
434aeebb RS |
1529 | /* A noswitch_section_callback for lcomm_section. */ |
1530 | ||
1531 | static bool | |
1532 | emit_local (tree decl ATTRIBUTE_UNUSED, | |
1533 | const char *name ATTRIBUTE_UNUSED, | |
1534 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
1535 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED) | |
1536 | { | |
1537 | #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL | |
1538 | ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, | |
1539 | size, DECL_ALIGN (decl)); | |
1540 | return true; | |
1541 | #elif defined ASM_OUTPUT_ALIGNED_LOCAL | |
1542 | ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl)); | |
1543 | return true; | |
b8694195 | 1544 | #else |
434aeebb RS |
1545 | ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded); |
1546 | return false; | |
b8694195 | 1547 | #endif |
434aeebb | 1548 | } |
b8694195 | 1549 | |
434aeebb RS |
1550 | /* A noswitch_section_callback for bss_noswitch_section. */ |
1551 | ||
1552 | #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS | |
1553 | static bool | |
1554 | emit_bss (tree decl ATTRIBUTE_UNUSED, | |
1555 | const char *name ATTRIBUTE_UNUSED, | |
1556 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
1557 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED) | |
1558 | { | |
b8694195 | 1559 | #if defined ASM_OUTPUT_ALIGNED_BSS |
434aeebb RS |
1560 | ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl)); |
1561 | return true; | |
b8694195 | 1562 | #else |
434aeebb RS |
1563 | ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded); |
1564 | return false; | |
b8694195 | 1565 | #endif |
434aeebb | 1566 | } |
b8694195 NC |
1567 | #endif |
1568 | ||
434aeebb RS |
1569 | /* A noswitch_section_callback for comm_section. */ |
1570 | ||
1571 | static bool | |
1572 | emit_common (tree decl ATTRIBUTE_UNUSED, | |
1573 | const char *name ATTRIBUTE_UNUSED, | |
1574 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
1575 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED) | |
1576 | { | |
b8694195 | 1577 | #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON |
434aeebb RS |
1578 | ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, |
1579 | size, DECL_ALIGN (decl)); | |
1580 | return true; | |
1581 | #elif defined ASM_OUTPUT_ALIGNED_COMMON | |
1582 | ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl)); | |
1583 | return true; | |
b8694195 | 1584 | #else |
434aeebb RS |
1585 | ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded); |
1586 | return false; | |
b8694195 | 1587 | #endif |
434aeebb RS |
1588 | } |
1589 | ||
1590 | /* A noswitch_section_callback for tls_comm_section. */ | |
b8694195 | 1591 | |
54fbf6a1 | 1592 | static bool |
434aeebb RS |
1593 | emit_tls_common (tree decl ATTRIBUTE_UNUSED, |
1594 | const char *name ATTRIBUTE_UNUSED, | |
1595 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
1596 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED) | |
b8694195 | 1597 | { |
434aeebb RS |
1598 | #ifdef ASM_OUTPUT_TLS_COMMON |
1599 | ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size); | |
1600 | return true; | |
54fbf6a1 | 1601 | #else |
434aeebb RS |
1602 | sorry ("thread-local COMMON data not implemented"); |
1603 | return true; | |
46f9491e | 1604 | #endif |
434aeebb | 1605 | } |
b8694195 | 1606 | |
434aeebb RS |
1607 | /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT. |
1608 | NAME is the name of DECL's SYMBOL_REF. */ | |
64270ab0 | 1609 | |
434aeebb RS |
1610 | static void |
1611 | assemble_noswitch_variable (tree decl, const char *name, section *sect) | |
1612 | { | |
1613 | unsigned HOST_WIDE_INT size, rounded; | |
ecb0eece | 1614 | |
434aeebb RS |
1615 | size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); |
1616 | rounded = size; | |
b8694195 | 1617 | |
434aeebb RS |
1618 | /* Don't allocate zero bytes of common, |
1619 | since that means "undefined external" in the linker. */ | |
1620 | if (size == 0) | |
1621 | rounded = 1; | |
1622 | ||
1623 | /* Round size up to multiple of BIGGEST_ALIGNMENT bits | |
1624 | so that each uninitialized object starts on such a boundary. */ | |
1625 | rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1; | |
1626 | rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
1627 | * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); | |
1628 | ||
1629 | if (!sect->noswitch.callback (decl, name, size, rounded) | |
1630 | && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded) | |
1631 | warning (0, "requested alignment for %q+D is greater than " | |
1632 | "implemented alignment of %wu", decl, rounded); | |
b8694195 NC |
1633 | } |
1634 | ||
aacd3885 RS |
1635 | /* A subroutine of assemble_variable. Output the label and contents of |
1636 | DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA | |
1637 | is as for assemble_variable. */ | |
1638 | ||
1639 | static void | |
1640 | assemble_variable_contents (tree decl, const char *name, | |
1641 | bool dont_output_data) | |
1642 | { | |
1643 | /* Do any machine/system dependent processing of the object. */ | |
1644 | #ifdef ASM_DECLARE_OBJECT_NAME | |
1645 | last_assemble_variable_decl = decl; | |
1646 | ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl); | |
1647 | #else | |
1648 | /* Standard thing is just output label for the object. */ | |
1649 | ASM_OUTPUT_LABEL (asm_out_file, name); | |
1650 | #endif /* ASM_DECLARE_OBJECT_NAME */ | |
1651 | ||
1652 | if (!dont_output_data) | |
1653 | { | |
1654 | if (DECL_INITIAL (decl) | |
1655 | && DECL_INITIAL (decl) != error_mark_node | |
1656 | && !initializer_zerop (DECL_INITIAL (decl))) | |
1657 | /* Output the actual data. */ | |
1658 | output_constant (DECL_INITIAL (decl), | |
1659 | tree_low_cst (DECL_SIZE_UNIT (decl), 1), | |
1660 | DECL_ALIGN (decl)); | |
1661 | else | |
1662 | /* Leave space for it. */ | |
1663 | assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1)); | |
1664 | } | |
1665 | } | |
1666 | ||
79e68feb RS |
1667 | /* Assemble everything that is needed for a variable or function declaration. |
1668 | Not used for automatic variables, and not used for function definitions. | |
1669 | Should not be called for variables of incomplete structure type. | |
1670 | ||
1671 | TOP_LEVEL is nonzero if this variable has file scope. | |
1672 | AT_END is nonzero if this is the special handling, at end of compilation, | |
ff8f4401 RS |
1673 | to define things that have had only tentative definitions. |
1674 | DONT_OUTPUT_DATA if nonzero means don't actually output the | |
1675 | initial value (that will be done by the caller). */ | |
79e68feb RS |
1676 | |
1677 | void | |
2e1eedd6 AJ |
1678 | assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED, |
1679 | int at_end ATTRIBUTE_UNUSED, int dont_output_data) | |
79e68feb | 1680 | { |
b3694847 | 1681 | const char *name; |
f8344bea | 1682 | unsigned int align; |
434aeebb RS |
1683 | rtx decl_rtl, symbol; |
1684 | section *sect; | |
79e68feb | 1685 | |
d35543c0 | 1686 | if (lang_hooks.decls.prepare_assemble_variable) |
ae2bcd98 | 1687 | lang_hooks.decls.prepare_assemble_variable (decl); |
d35543c0 | 1688 | |
cbed4565 RS |
1689 | last_assemble_variable_decl = 0; |
1690 | ||
d36d70cc | 1691 | /* Normally no need to say anything here for external references, |
9faa82d8 | 1692 | since assemble_external is called by the language-specific code |
d36d70cc | 1693 | when a declaration is first seen. */ |
79e68feb | 1694 | |
44fe2e80 | 1695 | if (DECL_EXTERNAL (decl)) |
79e68feb RS |
1696 | return; |
1697 | ||
1698 | /* Output no assembler code for a function declaration. | |
1699 | Only definitions of functions output anything. */ | |
1700 | ||
1701 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1702 | return; | |
1703 | ||
3914abb4 | 1704 | /* Do nothing for global register variables. */ |
f8cfc6aa | 1705 | if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl))) |
3914abb4 NB |
1706 | { |
1707 | TREE_ASM_WRITTEN (decl) = 1; | |
1708 | return; | |
1709 | } | |
1710 | ||
79e68feb RS |
1711 | /* If type was incomplete when the variable was declared, |
1712 | see if it is complete now. */ | |
1713 | ||
1714 | if (DECL_SIZE (decl) == 0) | |
1715 | layout_decl (decl, 0); | |
1716 | ||
1717 | /* Still incomplete => don't allocate it; treat the tentative defn | |
1718 | (which is what it must have been) as an `extern' reference. */ | |
1719 | ||
ff8f4401 | 1720 | if (!dont_output_data && DECL_SIZE (decl) == 0) |
79e68feb | 1721 | { |
dee15844 | 1722 | error ("storage size of %q+D isn%'t known", decl); |
1c1a7ba4 | 1723 | TREE_ASM_WRITTEN (decl) = 1; |
79e68feb RS |
1724 | return; |
1725 | } | |
1726 | ||
1727 | /* The first declaration of a variable that comes through this function | |
1728 | decides whether it is global (in C, has external linkage) | |
1729 | or local (in C, has internal linkage). So do nothing more | |
1730 | if this function has already run. */ | |
1731 | ||
1732 | if (TREE_ASM_WRITTEN (decl)) | |
1733 | return; | |
1734 | ||
fb49053f RH |
1735 | /* Make sure targetm.encode_section_info is invoked before we set |
1736 | ASM_WRITTEN. */ | |
17eee61c | 1737 | decl_rtl = DECL_RTL (decl); |
46f9491e | 1738 | |
79e68feb RS |
1739 | TREE_ASM_WRITTEN (decl) = 1; |
1740 | ||
3c350eb3 CB |
1741 | /* Do no output if -fsyntax-only. */ |
1742 | if (flag_syntax_only) | |
1743 | return; | |
1744 | ||
809d6575 | 1745 | app_disable (); |
79e68feb | 1746 | |
770ae6cc RK |
1747 | if (! dont_output_data |
1748 | && ! host_integerp (DECL_SIZE_UNIT (decl), 1)) | |
ff8f4401 | 1749 | { |
dee15844 | 1750 | error ("size of variable %q+D is too large", decl); |
544f03b4 | 1751 | return; |
79e68feb RS |
1752 | } |
1753 | ||
aacd3885 RS |
1754 | gcc_assert (MEM_P (decl_rtl)); |
1755 | gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF); | |
434aeebb RS |
1756 | symbol = XEXP (decl_rtl, 0); |
1757 | name = XSTR (symbol, 0); | |
810db579 JH |
1758 | if (TREE_PUBLIC (decl) && DECL_NAME (decl)) |
1759 | notice_global_symbol (decl); | |
f796d997 | 1760 | |
8a198bd2 JW |
1761 | /* Compute the alignment of this data. */ |
1762 | ||
1763 | align = DECL_ALIGN (decl); | |
1764 | ||
1765 | /* In the case for initialing an array whose length isn't specified, | |
1766 | where we have not yet been able to do the layout, | |
1767 | figure out the proper alignment now. */ | |
1768 | if (dont_output_data && DECL_SIZE (decl) == 0 | |
1769 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
1770 | align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl)))); | |
1771 | ||
1772 | /* Some object file formats have a maximum alignment which they support. | |
1773 | In particular, a.out format supports a maximum alignment of 4. */ | |
8a198bd2 JW |
1774 | if (align > MAX_OFILE_ALIGNMENT) |
1775 | { | |
dee15844 JM |
1776 | warning (0, "alignment of %q+D is greater than maximum object " |
1777 | "file alignment. Using %d", decl, | |
ddd2d57e | 1778 | MAX_OFILE_ALIGNMENT/BITS_PER_UNIT); |
8a198bd2 JW |
1779 | align = MAX_OFILE_ALIGNMENT; |
1780 | } | |
1781 | ||
1782 | /* On some machines, it is good to increase alignment sometimes. */ | |
51084e13 RH |
1783 | if (! DECL_USER_ALIGN (decl)) |
1784 | { | |
8a198bd2 | 1785 | #ifdef DATA_ALIGNMENT |
51084e13 | 1786 | align = DATA_ALIGNMENT (TREE_TYPE (decl), align); |
8a198bd2 JW |
1787 | #endif |
1788 | #ifdef CONSTANT_ALIGNMENT | |
51084e13 | 1789 | if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node) |
41077ce4 | 1790 | align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align); |
8a198bd2 | 1791 | #endif |
51084e13 | 1792 | } |
8a198bd2 JW |
1793 | |
1794 | /* Reset the alignment in case we have made it tighter, so we can benefit | |
1795 | from it in get_pointer_alignment. */ | |
1796 | DECL_ALIGN (decl) = align; | |
c952ff4b | 1797 | set_mem_align (decl_rtl, align); |
8a198bd2 | 1798 | |
b14707c3 RH |
1799 | if (TREE_PUBLIC (decl)) |
1800 | maybe_assemble_visibility (decl); | |
1801 | ||
8e3e233b DP |
1802 | if (DECL_PRESERVE_P (decl)) |
1803 | targetm.asm_out.mark_decl_preserved (name); | |
1804 | ||
79e68feb | 1805 | /* First make the assembler name(s) global if appropriate. */ |
434aeebb RS |
1806 | sect = get_variable_section (decl, false); |
1807 | if (TREE_PUBLIC (decl) | |
1808 | && DECL_NAME (decl) | |
1809 | && (sect->common.flags & SECTION_COMMON) == 0) | |
19c5b1cf | 1810 | globalize_decl (decl); |
79e68feb | 1811 | |
64270ab0 | 1812 | /* Output any data that we will need to use the address of. */ |
aacd3885 RS |
1813 | if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node) |
1814 | output_addressed_constants (DECL_INITIAL (decl)); | |
79e68feb | 1815 | |
a8e2f179 | 1816 | /* dbxout.c needs to know this. */ |
d6b5193b | 1817 | if (in_section && (in_section->common.flags & SECTION_CODE) != 0) |
a8e2f179 RS |
1818 | DECL_IN_TEXT_SECTION (decl) = 1; |
1819 | ||
aacd3885 RS |
1820 | /* If the decl is part of an object_block, make sure that the decl |
1821 | has been positioned within its block, but do not write out its | |
1822 | definition yet. output_object_blocks will do that later. */ | |
3fa9c136 | 1823 | if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol)) |
79e68feb | 1824 | { |
aacd3885 | 1825 | gcc_assert (!dont_output_data); |
434aeebb | 1826 | place_block_symbol (symbol); |
aacd3885 | 1827 | } |
434aeebb RS |
1828 | else if (SECTION_STYLE (sect) == SECTION_NOSWITCH) |
1829 | assemble_noswitch_variable (decl, name, sect); | |
aacd3885 RS |
1830 | else |
1831 | { | |
434aeebb | 1832 | switch_to_section (sect); |
aacd3885 RS |
1833 | if (align > BITS_PER_UNIT) |
1834 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl))); | |
1835 | assemble_variable_contents (decl, name, dont_output_data); | |
79e68feb | 1836 | } |
79e68feb RS |
1837 | } |
1838 | ||
2e9effae RS |
1839 | /* Return 1 if type TYPE contains any pointers. */ |
1840 | ||
1841 | static int | |
2e1eedd6 | 1842 | contains_pointers_p (tree type) |
2e9effae RS |
1843 | { |
1844 | switch (TREE_CODE (type)) | |
1845 | { | |
1846 | case POINTER_TYPE: | |
1847 | case REFERENCE_TYPE: | |
1848 | /* I'm not sure whether OFFSET_TYPE needs this treatment, | |
1849 | so I'll play safe and return 1. */ | |
1850 | case OFFSET_TYPE: | |
1851 | return 1; | |
1852 | ||
1853 | case RECORD_TYPE: | |
1854 | case UNION_TYPE: | |
1855 | case QUAL_UNION_TYPE: | |
1856 | { | |
1857 | tree fields; | |
1858 | /* For a type that has fields, see if the fields have pointers. */ | |
1859 | for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields)) | |
ce49ea8a JM |
1860 | if (TREE_CODE (fields) == FIELD_DECL |
1861 | && contains_pointers_p (TREE_TYPE (fields))) | |
2e9effae RS |
1862 | return 1; |
1863 | return 0; | |
1864 | } | |
1865 | ||
1866 | case ARRAY_TYPE: | |
1867 | /* An array type contains pointers if its element type does. */ | |
1868 | return contains_pointers_p (TREE_TYPE (type)); | |
1869 | ||
1870 | default: | |
1871 | return 0; | |
1872 | } | |
1873 | } | |
1874 | ||
857e7259 ZW |
1875 | /* In unit-at-a-time mode, we delay assemble_external processing until |
1876 | the compilation unit is finalized. This is the best we can do for | |
1877 | right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay | |
1878 | it all the way to final. See PR 17982 for further discussion. */ | |
1879 | static GTY(()) tree pending_assemble_externals; | |
1880 | ||
9be6533a RS |
1881 | #ifdef ASM_OUTPUT_EXTERNAL |
1882 | /* True if DECL is a function decl for which no out-of-line copy exists. | |
1883 | It is assumed that DECL's assembler name has been set. */ | |
1884 | ||
1885 | static bool | |
1886 | incorporeal_function_p (tree decl) | |
1887 | { | |
1888 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl)) | |
1889 | { | |
1890 | const char *name; | |
1891 | ||
1892 | if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL | |
1893 | && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA) | |
1894 | return true; | |
1895 | ||
1896 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
1897 | if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0) | |
1898 | return true; | |
1899 | } | |
1900 | return false; | |
1901 | } | |
857e7259 ZW |
1902 | |
1903 | /* Actually do the tests to determine if this is necessary, and invoke | |
1904 | ASM_OUTPUT_EXTERNAL. */ | |
1905 | static void | |
1906 | assemble_external_real (tree decl) | |
1907 | { | |
1908 | rtx rtl = DECL_RTL (decl); | |
1909 | ||
1910 | if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF | |
1911 | && !SYMBOL_REF_USED (XEXP (rtl, 0)) | |
1912 | && !incorporeal_function_p (decl)) | |
1913 | { | |
1914 | /* Some systems do require some output. */ | |
1915 | SYMBOL_REF_USED (XEXP (rtl, 0)) = 1; | |
1916 | ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0)); | |
1917 | } | |
1918 | } | |
1919 | #endif | |
1920 | ||
1921 | void | |
1922 | process_pending_assemble_externals (void) | |
1923 | { | |
1924 | #ifdef ASM_OUTPUT_EXTERNAL | |
1925 | tree list; | |
1926 | for (list = pending_assemble_externals; list; list = TREE_CHAIN (list)) | |
1927 | assemble_external_real (TREE_VALUE (list)); | |
1928 | ||
1929 | pending_assemble_externals = 0; | |
9be6533a | 1930 | #endif |
857e7259 | 1931 | } |
9be6533a | 1932 | |
79e68feb | 1933 | /* Output something to declare an external symbol to the assembler. |
fff9e713 MT |
1934 | (Most assemblers don't need this, so we normally output nothing.) |
1935 | Do nothing if DECL is not external. */ | |
79e68feb RS |
1936 | |
1937 | void | |
2e1eedd6 | 1938 | assemble_external (tree decl ATTRIBUTE_UNUSED) |
79e68feb | 1939 | { |
e6855a2d MM |
1940 | /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the |
1941 | main body of this code is only rarely exercised. To provide some | |
1942 | testing, on all platforms, we make sure that the ASM_OUT_FILE is | |
1943 | open. If it's not, we should not be calling this function. */ | |
857e7259 | 1944 | gcc_assert (asm_out_file); |
e6855a2d | 1945 | |
79e68feb | 1946 | #ifdef ASM_OUTPUT_EXTERNAL |
857e7259 ZW |
1947 | if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl)) |
1948 | return; | |
fff9e713 | 1949 | |
857e7259 ZW |
1950 | if (flag_unit_at_a_time) |
1951 | pending_assemble_externals = tree_cons (0, decl, | |
1952 | pending_assemble_externals); | |
1953 | else | |
1954 | assemble_external_real (decl); | |
79e68feb RS |
1955 | #endif |
1956 | } | |
1957 | ||
1958 | /* Similar, for calling a library function FUN. */ | |
1959 | ||
1960 | void | |
6773a41c | 1961 | assemble_external_libcall (rtx fun) |
79e68feb | 1962 | { |
b93a436e JL |
1963 | /* Declare library function name external when first used, if nec. */ |
1964 | if (! SYMBOL_REF_USED (fun)) | |
79e68feb | 1965 | { |
b93a436e | 1966 | SYMBOL_REF_USED (fun) = 1; |
5fd9b178 | 1967 | targetm.asm_out.external_libcall (fun); |
79e68feb | 1968 | } |
79e68feb RS |
1969 | } |
1970 | ||
79e68feb RS |
1971 | /* Assemble a label named NAME. */ |
1972 | ||
1973 | void | |
2e1eedd6 | 1974 | assemble_label (const char *name) |
79e68feb | 1975 | { |
b93a436e | 1976 | ASM_OUTPUT_LABEL (asm_out_file, name); |
79e68feb RS |
1977 | } |
1978 | ||
bb9a388d | 1979 | /* Set the symbol_referenced flag for ID. */ |
4d7d0451 | 1980 | void |
2e1eedd6 | 1981 | mark_referenced (tree id) |
4d7d0451 | 1982 | { |
4d7d0451 JH |
1983 | TREE_SYMBOL_REFERENCED (id) = 1; |
1984 | } | |
1985 | ||
bb9a388d ZW |
1986 | /* Set the symbol_referenced flag for DECL and notify callgraph. */ |
1987 | void | |
1988 | mark_decl_referenced (tree decl) | |
1989 | { | |
1990 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
5c55c2e8 | 1991 | { |
8634c649 JJ |
1992 | /* Extern inline functions don't become needed when referenced. |
1993 | If we know a method will be emitted in other TU and no new | |
1994 | functions can be marked reachable, just use the external | |
1995 | definition. */ | |
1996 | struct cgraph_node *node = cgraph_node (decl); | |
1997 | if (!DECL_EXTERNAL (decl) | |
1998 | && (!node->local.vtable_method || !cgraph_global_info_ready | |
1999 | || !node->local.finalized)) | |
2000 | cgraph_mark_needed_node (node); | |
5c55c2e8 | 2001 | } |
bb9a388d | 2002 | else if (TREE_CODE (decl) == VAR_DECL) |
cd9c7bd2 JH |
2003 | { |
2004 | struct cgraph_varpool_node *node = cgraph_varpool_node (decl); | |
2005 | cgraph_varpool_mark_needed_node (node); | |
2006 | /* C++ frontend use mark_decl_references to force COMDAT variables | |
2007 | to be output that might appear dead otherwise. */ | |
2008 | node->force_output = true; | |
2009 | } | |
bb9a388d ZW |
2010 | /* else do nothing - we can get various sorts of CST nodes here, |
2011 | which do not need to be marked. */ | |
2012 | } | |
2013 | ||
2979bcca AO |
2014 | |
2015 | /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS | |
2016 | until we find an identifier that is not itself a transparent alias. | |
2017 | Modify the alias passed to it by reference (and all aliases on the | |
2018 | way to the ultimate target), such that they do not have to be | |
2019 | followed again, and return the ultimate target of the alias | |
2020 | chain. */ | |
2021 | ||
a0203ca7 AO |
2022 | static inline tree |
2023 | ultimate_transparent_alias_target (tree *alias) | |
2024 | { | |
2025 | tree target = *alias; | |
2026 | ||
2027 | if (IDENTIFIER_TRANSPARENT_ALIAS (target)) | |
2028 | { | |
2029 | gcc_assert (TREE_CHAIN (target)); | |
2030 | target = ultimate_transparent_alias_target (&TREE_CHAIN (target)); | |
2031 | gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target) | |
2032 | && ! TREE_CHAIN (target)); | |
2033 | *alias = target; | |
2034 | } | |
2035 | ||
2036 | return target; | |
2037 | } | |
2038 | ||
57829bc4 MM |
2039 | /* Output to FILE (an assembly file) a reference to NAME. If NAME |
2040 | starts with a *, the rest of NAME is output verbatim. Otherwise | |
2041 | NAME is transformed in a target-specific way (usually by the | |
2042 | addition of an underscore). */ | |
2043 | ||
2044 | void | |
2045 | assemble_name_raw (FILE *file, const char *name) | |
2046 | { | |
2047 | if (name[0] == '*') | |
2048 | fputs (&name[1], file); | |
2049 | else | |
2050 | ASM_OUTPUT_LABELREF (file, name); | |
2051 | } | |
2052 | ||
2053 | /* Like assemble_name_raw, but should be used when NAME might refer to | |
2054 | an entity that is also represented as a tree (like a function or | |
2055 | variable). If NAME does refer to such an entity, that entity will | |
2056 | be marked as referenced. */ | |
79e68feb RS |
2057 | |
2058 | void | |
2e1eedd6 | 2059 | assemble_name (FILE *file, const char *name) |
79e68feb | 2060 | { |
ec940faa | 2061 | const char *real_name; |
a94dbf2c | 2062 | tree id; |
648fb7cf | 2063 | |
245f1bfa | 2064 | real_name = targetm.strip_name_encoding (name); |
87907387 | 2065 | |
a94dbf2c JM |
2066 | id = maybe_get_identifier (real_name); |
2067 | if (id) | |
a0203ca7 | 2068 | { |
a114b455 AO |
2069 | tree id_orig = id; |
2070 | ||
a0203ca7 AO |
2071 | mark_referenced (id); |
2072 | ultimate_transparent_alias_target (&id); | |
a114b455 AO |
2073 | if (id != id_orig) |
2074 | name = IDENTIFIER_POINTER (id); | |
a0203ca7 AO |
2075 | gcc_assert (! TREE_CHAIN (id)); |
2076 | } | |
03e42132 | 2077 | |
57829bc4 | 2078 | assemble_name_raw (file, name); |
79e68feb RS |
2079 | } |
2080 | ||
2081 | /* Allocate SIZE bytes writable static space with a gensym name | |
2082 | and return an RTX to refer to its address. */ | |
2083 | ||
2084 | rtx | |
2e1eedd6 | 2085 | assemble_static_space (unsigned HOST_WIDE_INT size) |
79e68feb RS |
2086 | { |
2087 | char name[12]; | |
520a57c8 | 2088 | const char *namestring; |
79e68feb | 2089 | rtx x; |
79e68feb | 2090 | |
79e68feb RS |
2091 | ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno); |
2092 | ++const_labelno; | |
a8a05998 | 2093 | namestring = ggc_strdup (name); |
79e68feb | 2094 | |
b93a436e | 2095 | x = gen_rtx_SYMBOL_REF (Pmode, namestring); |
52859c77 | 2096 | SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL; |
ca695ac9 | 2097 | |
e9a25f70 | 2098 | #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL |
b93a436e JL |
2099 | ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size, |
2100 | BIGGEST_ALIGNMENT); | |
e9a25f70 | 2101 | #else |
79e68feb | 2102 | #ifdef ASM_OUTPUT_ALIGNED_LOCAL |
b93a436e | 2103 | ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT); |
79e68feb | 2104 | #else |
e016950d KG |
2105 | { |
2106 | /* Round size up to multiple of BIGGEST_ALIGNMENT bits | |
2107 | so that each uninitialized object starts on such a boundary. */ | |
2d76cb1a | 2108 | /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */ |
58e15542 | 2109 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED |
47c3ed98 KG |
2110 | = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1) |
2111 | / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
2112 | * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); | |
e016950d KG |
2113 | ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded); |
2114 | } | |
e9a25f70 | 2115 | #endif |
79e68feb RS |
2116 | #endif |
2117 | return x; | |
2118 | } | |
2119 | ||
2120 | /* Assemble the static constant template for function entry trampolines. | |
2121 | This is done at most once per compilation. | |
2122 | Returns an RTX for the address of the template. */ | |
2123 | ||
6de9cd9a DN |
2124 | static GTY(()) rtx initial_trampoline; |
2125 | ||
f0e969bd | 2126 | #ifdef TRAMPOLINE_TEMPLATE |
79e68feb | 2127 | rtx |
2e1eedd6 | 2128 | assemble_trampoline_template (void) |
79e68feb RS |
2129 | { |
2130 | char label[256]; | |
fc608b03 | 2131 | const char *name; |
79e68feb | 2132 | int align; |
52859c77 | 2133 | rtx symbol; |
79e68feb | 2134 | |
6de9cd9a DN |
2135 | if (initial_trampoline) |
2136 | return initial_trampoline; | |
2137 | ||
37552631 | 2138 | /* By default, put trampoline templates in read-only data section. */ |
f49acdb4 | 2139 | |
37552631 | 2140 | #ifdef TRAMPOLINE_SECTION |
d6b5193b | 2141 | switch_to_section (TRAMPOLINE_SECTION); |
37552631 | 2142 | #else |
d6b5193b | 2143 | switch_to_section (readonly_data_section); |
37552631 | 2144 | #endif |
f49acdb4 | 2145 | |
79e68feb | 2146 | /* Write the assembler code to define one. */ |
073b0524 | 2147 | align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); |
79e68feb | 2148 | if (align > 0) |
91ea4f8d KG |
2149 | { |
2150 | ASM_OUTPUT_ALIGN (asm_out_file, align); | |
2151 | } | |
79e68feb | 2152 | |
5fd9b178 | 2153 | targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0); |
79e68feb RS |
2154 | TRAMPOLINE_TEMPLATE (asm_out_file); |
2155 | ||
2156 | /* Record the rtl to refer to it. */ | |
2157 | ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0); | |
a8a05998 | 2158 | name = ggc_strdup (label); |
52859c77 RH |
2159 | symbol = gen_rtx_SYMBOL_REF (Pmode, name); |
2160 | SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL; | |
2161 | ||
6de9cd9a DN |
2162 | initial_trampoline = gen_rtx_MEM (BLKmode, symbol); |
2163 | set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT); | |
2164 | ||
2165 | return initial_trampoline; | |
79e68feb | 2166 | } |
f0e969bd | 2167 | #endif |
79e68feb | 2168 | \f |
c8af3574 RH |
2169 | /* A and B are either alignments or offsets. Return the minimum alignment |
2170 | that may be assumed after adding the two together. */ | |
2171 | ||
2172 | static inline unsigned | |
2e1eedd6 | 2173 | min_align (unsigned int a, unsigned int b) |
c8af3574 RH |
2174 | { |
2175 | return (a | b) & -(a | b); | |
2176 | } | |
79e68feb | 2177 | |
301d03af RS |
2178 | /* Return the assembler directive for creating a given kind of integer |
2179 | object. SIZE is the number of bytes in the object and ALIGNED_P | |
2180 | indicates whether it is known to be aligned. Return NULL if the | |
2181 | assembly dialect has no such directive. | |
79e68feb | 2182 | |
301d03af RS |
2183 | The returned string should be printed at the start of a new line and |
2184 | be followed immediately by the object's initial value. */ | |
2185 | ||
2186 | const char * | |
2e1eedd6 | 2187 | integer_asm_op (int size, int aligned_p) |
79e68feb | 2188 | { |
301d03af | 2189 | struct asm_int_op *ops; |
79e68feb | 2190 | |
301d03af RS |
2191 | if (aligned_p) |
2192 | ops = &targetm.asm_out.aligned_op; | |
c8af3574 | 2193 | else |
301d03af RS |
2194 | ops = &targetm.asm_out.unaligned_op; |
2195 | ||
2196 | switch (size) | |
c8af3574 | 2197 | { |
301d03af RS |
2198 | case 1: |
2199 | return targetm.asm_out.byte_op; | |
2200 | case 2: | |
2201 | return ops->hi; | |
2202 | case 4: | |
2203 | return ops->si; | |
2204 | case 8: | |
2205 | return ops->di; | |
2206 | case 16: | |
2207 | return ops->ti; | |
2208 | default: | |
2209 | return NULL; | |
2210 | } | |
2211 | } | |
c8af3574 | 2212 | |
301d03af RS |
2213 | /* Use directive OP to assemble an integer object X. Print OP at the |
2214 | start of the line, followed immediately by the value of X. */ | |
c8af3574 | 2215 | |
301d03af | 2216 | void |
2e1eedd6 | 2217 | assemble_integer_with_op (const char *op, rtx x) |
301d03af RS |
2218 | { |
2219 | fputs (op, asm_out_file); | |
2220 | output_addr_const (asm_out_file, x); | |
2221 | fputc ('\n', asm_out_file); | |
2222 | } | |
79e68feb | 2223 | |
301d03af | 2224 | /* The default implementation of the asm_out.integer target hook. */ |
79e68feb | 2225 | |
301d03af | 2226 | bool |
2e1eedd6 AJ |
2227 | default_assemble_integer (rtx x ATTRIBUTE_UNUSED, |
2228 | unsigned int size ATTRIBUTE_UNUSED, | |
2229 | int aligned_p ATTRIBUTE_UNUSED) | |
301d03af RS |
2230 | { |
2231 | const char *op = integer_asm_op (size, aligned_p); | |
d31f3604 PB |
2232 | /* Avoid GAS bugs for large values. Specifically negative values whose |
2233 | absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */ | |
2234 | if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT) | |
a13fd905 | 2235 | return false; |
301d03af RS |
2236 | return op && (assemble_integer_with_op (op, x), true); |
2237 | } | |
79e68feb | 2238 | |
301d03af RS |
2239 | /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is |
2240 | the alignment of the integer in bits. Return 1 if we were able to output | |
41806d92 NS |
2241 | the constant, otherwise 0. We must be able to output the constant, |
2242 | if FORCE is nonzero. */ | |
79e68feb | 2243 | |
301d03af | 2244 | bool |
2e1eedd6 | 2245 | assemble_integer (rtx x, unsigned int size, unsigned int align, int force) |
301d03af RS |
2246 | { |
2247 | int aligned_p; | |
79e68feb | 2248 | |
301d03af | 2249 | aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT)); |
79e68feb | 2250 | |
301d03af | 2251 | /* See if the target hook can handle this kind of object. */ |
5fd9b178 | 2252 | if (targetm.asm_out.integer (x, size, aligned_p)) |
301d03af | 2253 | return true; |
79e68feb | 2254 | |
301d03af RS |
2255 | /* If the object is a multi-byte one, try splitting it up. Split |
2256 | it into words it if is multi-word, otherwise split it into bytes. */ | |
2257 | if (size > 1) | |
c8af3574 RH |
2258 | { |
2259 | enum machine_mode omode, imode; | |
301d03af RS |
2260 | unsigned int subalign; |
2261 | unsigned int subsize, i; | |
46f9491e | 2262 | |
301d03af RS |
2263 | subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1; |
2264 | subalign = MIN (align, subsize * BITS_PER_UNIT); | |
2265 | omode = mode_for_size (subsize * BITS_PER_UNIT, MODE_INT, 0); | |
c8af3574 RH |
2266 | imode = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0); |
2267 | ||
301d03af | 2268 | for (i = 0; i < size; i += subsize) |
c8af3574 | 2269 | { |
301d03af RS |
2270 | rtx partial = simplify_subreg (omode, x, imode, i); |
2271 | if (!partial || !assemble_integer (partial, subsize, subalign, 0)) | |
c8af3574 RH |
2272 | break; |
2273 | } | |
c8af3574 | 2274 | if (i == size) |
301d03af RS |
2275 | return true; |
2276 | ||
2277 | /* If we've printed some of it, but not all of it, there's no going | |
2278 | back now. */ | |
fbc848cc | 2279 | gcc_assert (!i); |
c8af3574 RH |
2280 | } |
2281 | ||
fbc848cc | 2282 | gcc_assert (!force); |
083cad55 | 2283 | |
301d03af | 2284 | return false; |
79e68feb RS |
2285 | } |
2286 | \f | |
82af613f | 2287 | void |
2e1eedd6 | 2288 | assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align) |
94aca342 | 2289 | { |
5e5cf1ee | 2290 | long data[4] = {0, 0, 0, 0}; |
b409761a ZW |
2291 | int i; |
2292 | int bitsize, nelts, nunits, units_per; | |
2293 | ||
02befdf4 | 2294 | /* This is hairy. We have a quantity of known size. real_to_target |
b409761a ZW |
2295 | will put it into an array of *host* longs, 32 bits per element |
2296 | (even if long is more than 32 bits). We need to determine the | |
2297 | number of array elements that are occupied (nelts) and the number | |
2298 | of *target* min-addressable units that will be occupied in the | |
02befdf4 ZW |
2299 | object file (nunits). We cannot assume that 32 divides the |
2300 | mode's bitsize (size * BITS_PER_UNIT) evenly. | |
2301 | ||
2302 | size * BITS_PER_UNIT is used here to make sure that padding bits | |
2303 | (which might appear at either end of the value; real_to_target | |
2304 | will include the padding bits in its output array) are included. */ | |
2305 | ||
2306 | nunits = GET_MODE_SIZE (mode); | |
2307 | bitsize = nunits * BITS_PER_UNIT; | |
b409761a ZW |
2308 | nelts = CEIL (bitsize, 32); |
2309 | units_per = 32 / BITS_PER_UNIT; | |
2310 | ||
2311 | real_to_target (data, &d, mode); | |
2312 | ||
2313 | /* Put out the first word with the specified alignment. */ | |
2314 | assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1); | |
2315 | nunits -= units_per; | |
2316 | ||
2317 | /* Subsequent words need only 32-bit alignment. */ | |
2318 | align = min_align (align, 32); | |
2319 | ||
2320 | for (i = 1; i < nelts; i++) | |
79e68feb | 2321 | { |
b409761a ZW |
2322 | assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1); |
2323 | nunits -= units_per; | |
79e68feb | 2324 | } |
94aca342 | 2325 | } |
79e68feb | 2326 | \f |
79e68feb RS |
2327 | /* Given an expression EXP with a constant value, |
2328 | reduce it to the sum of an assembler symbol and an integer. | |
2329 | Store them both in the structure *VALUE. | |
04c7ae48 | 2330 | EXP must be reducible. */ |
79e68feb | 2331 | |
e2500fed | 2332 | struct addr_const GTY(()) |
79e68feb RS |
2333 | { |
2334 | rtx base; | |
fb351073 | 2335 | HOST_WIDE_INT offset; |
79e68feb RS |
2336 | }; |
2337 | ||
2338 | static void | |
2e1eedd6 | 2339 | decode_addr_const (tree exp, struct addr_const *value) |
79e68feb | 2340 | { |
b3694847 SS |
2341 | tree target = TREE_OPERAND (exp, 0); |
2342 | int offset = 0; | |
2343 | rtx x; | |
79e68feb RS |
2344 | |
2345 | while (1) | |
2346 | { | |
2347 | if (TREE_CODE (target) == COMPONENT_REF | |
770ae6cc | 2348 | && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0)) |
665f2503 | 2349 | |
79e68feb | 2350 | { |
770ae6cc | 2351 | offset += int_byte_position (TREE_OPERAND (target, 1)); |
79e68feb RS |
2352 | target = TREE_OPERAND (target, 0); |
2353 | } | |
b4e3fabb RK |
2354 | else if (TREE_CODE (target) == ARRAY_REF |
2355 | || TREE_CODE (target) == ARRAY_RANGE_REF) | |
79e68feb | 2356 | { |
770ae6cc RK |
2357 | offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1) |
2358 | * tree_low_cst (TREE_OPERAND (target, 1), 0)); | |
79e68feb RS |
2359 | target = TREE_OPERAND (target, 0); |
2360 | } | |
2361 | else | |
2362 | break; | |
2363 | } | |
2364 | ||
2365 | switch (TREE_CODE (target)) | |
2366 | { | |
2367 | case VAR_DECL: | |
2368 | case FUNCTION_DECL: | |
2369 | x = DECL_RTL (target); | |
2370 | break; | |
2371 | ||
2372 | case LABEL_DECL: | |
b93a436e | 2373 | x = gen_rtx_MEM (FUNCTION_MODE, |
4c33cb26 | 2374 | gen_rtx_LABEL_REF (Pmode, force_label_rtx (target))); |
79e68feb RS |
2375 | break; |
2376 | ||
2377 | case REAL_CST: | |
2378 | case STRING_CST: | |
2379 | case COMPLEX_CST: | |
2380 | case CONSTRUCTOR: | |
2cf55b55 | 2381 | case INTEGER_CST: |
44e3910a | 2382 | x = output_constant_def (target, 1); |
79e68feb RS |
2383 | break; |
2384 | ||
2385 | default: | |
fbc848cc | 2386 | gcc_unreachable (); |
79e68feb RS |
2387 | } |
2388 | ||
fbc848cc | 2389 | gcc_assert (MEM_P (x)); |
b93a436e | 2390 | x = XEXP (x, 0); |
79e68feb RS |
2391 | |
2392 | value->base = x; | |
2393 | value->offset = offset; | |
2394 | } | |
2395 | \f | |
2396 | /* Uniquize all constants that appear in memory. | |
2397 | Each constant in memory thus far output is recorded | |
5e9295fa | 2398 | in `const_desc_table'. */ |
79e68feb | 2399 | |
e2500fed | 2400 | struct constant_descriptor_tree GTY(()) |
79e68feb | 2401 | { |
e2500fed | 2402 | /* A MEM for the constant. */ |
14a774a9 | 2403 | rtx rtl; |
e2500fed GK |
2404 | |
2405 | /* The value of the constant. */ | |
2406 | tree value; | |
b96917bf JJ |
2407 | |
2408 | /* Hash of value. Computing the hash from value each time | |
2409 | hashfn is called can't work properly, as that means recursive | |
2410 | use of the hash table during hash table expansion. */ | |
2411 | hashval_t hash; | |
79e68feb RS |
2412 | }; |
2413 | ||
10b6a274 ZW |
2414 | static GTY((param_is (struct constant_descriptor_tree))) |
2415 | htab_t const_desc_htab; | |
79e68feb | 2416 | |
2e1eedd6 AJ |
2417 | static struct constant_descriptor_tree * build_constant_desc (tree); |
2418 | static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int); | |
bd7cf17e | 2419 | |
79e68feb RS |
2420 | /* Compute a hash code for a constant expression. */ |
2421 | ||
10b6a274 | 2422 | static hashval_t |
2e1eedd6 | 2423 | const_desc_hash (const void *ptr) |
46b33600 | 2424 | { |
b96917bf | 2425 | return ((struct constant_descriptor_tree *)ptr)->hash; |
46b33600 RH |
2426 | } |
2427 | ||
10b6a274 | 2428 | static hashval_t |
2e1eedd6 | 2429 | const_hash_1 (const tree exp) |
79e68feb | 2430 | { |
b3694847 | 2431 | const char *p; |
10b6a274 | 2432 | hashval_t hi; |
46b33600 | 2433 | int len, i; |
b3694847 | 2434 | enum tree_code code = TREE_CODE (exp); |
79e68feb | 2435 | |
a9d07d6e RK |
2436 | /* Either set P and LEN to the address and len of something to hash and |
2437 | exit the switch or return a value. */ | |
2438 | ||
2439 | switch (code) | |
79e68feb | 2440 | { |
a9d07d6e | 2441 | case INTEGER_CST: |
2afaa41c GM |
2442 | p = (char *) &TREE_INT_CST (exp); |
2443 | len = sizeof TREE_INT_CST (exp); | |
a9d07d6e RK |
2444 | break; |
2445 | ||
2446 | case REAL_CST: | |
46b33600 | 2447 | return real_hash (TREE_REAL_CST_PTR (exp)); |
79e68feb | 2448 | |
a9d07d6e | 2449 | case STRING_CST: |
3521b33c ZW |
2450 | p = TREE_STRING_POINTER (exp); |
2451 | len = TREE_STRING_LENGTH (exp); | |
a9d07d6e | 2452 | break; |
5e9295fa | 2453 | |
a9d07d6e | 2454 | case COMPLEX_CST: |
46b33600 RH |
2455 | return (const_hash_1 (TREE_REALPART (exp)) * 5 |
2456 | + const_hash_1 (TREE_IMAGPART (exp))); | |
a9d07d6e RK |
2457 | |
2458 | case CONSTRUCTOR: | |
08f2586c | 2459 | { |
4038c495 GB |
2460 | unsigned HOST_WIDE_INT idx; |
2461 | tree value; | |
083cad55 | 2462 | |
08f2586c | 2463 | hi = 5 + int_size_in_bytes (TREE_TYPE (exp)); |
083cad55 | 2464 | |
4038c495 GB |
2465 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value) |
2466 | if (value) | |
2467 | hi = hi * 603 + const_hash_1 (value); | |
083cad55 | 2468 | |
08f2586c NS |
2469 | return hi; |
2470 | } | |
79e68feb | 2471 | |
a9d07d6e | 2472 | case ADDR_EXPR: |
5d056e9b | 2473 | case FDESC_EXPR: |
a9d07d6e RK |
2474 | { |
2475 | struct addr_const value; | |
2476 | ||
2477 | decode_addr_const (exp, &value); | |
fbc848cc | 2478 | switch (GET_CODE (value.base)) |
a9d07d6e | 2479 | { |
fbc848cc | 2480 | case SYMBOL_REF: |
a9d07d6e RK |
2481 | /* Don't hash the address of the SYMBOL_REF; |
2482 | only use the offset and the symbol name. */ | |
2483 | hi = value.offset; | |
2484 | p = XSTR (value.base, 0); | |
2485 | for (i = 0; p[i] != 0; i++) | |
2486 | hi = ((hi * 613) + (unsigned) (p[i])); | |
fbc848cc NS |
2487 | break; |
2488 | ||
2489 | case LABEL_REF: | |
2490 | hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13; | |
2491 | break; | |
2492 | ||
2493 | default: | |
2494 | gcc_unreachable (); | |
a9d07d6e | 2495 | } |
a9d07d6e | 2496 | } |
79e68feb | 2497 | return hi; |
a9d07d6e RK |
2498 | |
2499 | case PLUS_EXPR: | |
2500 | case MINUS_EXPR: | |
46b33600 RH |
2501 | return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9 |
2502 | + const_hash_1 (TREE_OPERAND (exp, 1))); | |
a9d07d6e RK |
2503 | |
2504 | case NOP_EXPR: | |
2505 | case CONVERT_EXPR: | |
2506 | case NON_LVALUE_EXPR: | |
46b33600 | 2507 | return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2; |
46f9491e | 2508 | |
e9a25f70 | 2509 | default: |
2d76cb1a | 2510 | /* A language specific constant. Just hash the code. */ |
46b33600 | 2511 | return code; |
79e68feb | 2512 | } |
79e68feb | 2513 | |
f9da5064 | 2514 | /* Compute hashing function. */ |
79e68feb RS |
2515 | hi = len; |
2516 | for (i = 0; i < len; i++) | |
0f41302f | 2517 | hi = ((hi * 613) + (unsigned) (p[i])); |
79e68feb | 2518 | |
79e68feb RS |
2519 | return hi; |
2520 | } | |
79e68feb | 2521 | |
10b6a274 ZW |
2522 | /* Wrapper of compare_constant, for the htab interface. */ |
2523 | static int | |
2e1eedd6 | 2524 | const_desc_eq (const void *p1, const void *p2) |
10b6a274 | 2525 | { |
b96917bf JJ |
2526 | const struct constant_descriptor_tree *c1 = p1; |
2527 | const struct constant_descriptor_tree *c2 = p2; | |
2528 | if (c1->hash != c2->hash) | |
2529 | return 0; | |
2530 | return compare_constant (c1->value, c2->value); | |
10b6a274 ZW |
2531 | } |
2532 | ||
e2500fed GK |
2533 | /* Compare t1 and t2, and return 1 only if they are known to result in |
2534 | the same bit pattern on output. */ | |
79e68feb | 2535 | |
e2500fed | 2536 | static int |
2e1eedd6 | 2537 | compare_constant (const tree t1, const tree t2) |
79e68feb | 2538 | { |
e2500fed | 2539 | enum tree_code typecode; |
79e68feb | 2540 | |
e2500fed GK |
2541 | if (t1 == NULL_TREE) |
2542 | return t2 == NULL_TREE; | |
2543 | if (t2 == NULL_TREE) | |
79e68feb RS |
2544 | return 0; |
2545 | ||
e2500fed GK |
2546 | if (TREE_CODE (t1) != TREE_CODE (t2)) |
2547 | return 0; | |
a9d07d6e | 2548 | |
e2500fed | 2549 | switch (TREE_CODE (t1)) |
79e68feb | 2550 | { |
a9d07d6e | 2551 | case INTEGER_CST: |
79e68feb | 2552 | /* Integer constants are the same only if the same width of type. */ |
e2500fed | 2553 | if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2))) |
79e68feb | 2554 | return 0; |
6a34c788 RS |
2555 | if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))) |
2556 | return 0; | |
e2500fed | 2557 | return tree_int_cst_equal (t1, t2); |
a9d07d6e RK |
2558 | |
2559 | case REAL_CST: | |
79e68feb | 2560 | /* Real constants are the same only if the same width of type. */ |
e2500fed | 2561 | if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2))) |
79e68feb | 2562 | return 0; |
a9d07d6e | 2563 | |
e2500fed | 2564 | return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); |
a9d07d6e RK |
2565 | |
2566 | case STRING_CST: | |
e2500fed | 2567 | if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))) |
79e68feb | 2568 | return 0; |
a9d07d6e | 2569 | |
e2500fed GK |
2570 | return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) |
2571 | && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), | |
2572 | TREE_STRING_LENGTH (t1))); | |
79e68feb | 2573 | |
a9d07d6e | 2574 | case COMPLEX_CST: |
e2500fed GK |
2575 | return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2)) |
2576 | && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2))); | |
79e68feb | 2577 | |
a9d07d6e | 2578 | case CONSTRUCTOR: |
08f2586c | 2579 | { |
4038c495 GB |
2580 | VEC(constructor_elt, gc) *v1, *v2; |
2581 | unsigned HOST_WIDE_INT idx; | |
083cad55 | 2582 | |
08f2586c NS |
2583 | typecode = TREE_CODE (TREE_TYPE (t1)); |
2584 | if (typecode != TREE_CODE (TREE_TYPE (t2))) | |
2585 | return 0; | |
a9d07d6e | 2586 | |
08f2586c NS |
2587 | if (typecode == ARRAY_TYPE) |
2588 | { | |
2589 | HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1)); | |
2590 | /* For arrays, check that the sizes all match. */ | |
2591 | if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)) | |
2592 | || size_1 == -1 | |
2593 | || size_1 != int_size_in_bytes (TREE_TYPE (t2))) | |
2594 | return 0; | |
2595 | } | |
2596 | else | |
2597 | { | |
2598 | /* For record and union constructors, require exact type | |
2599 | equality. */ | |
2600 | if (TREE_TYPE (t1) != TREE_TYPE (t2)) | |
2601 | return 0; | |
2602 | } | |
b2e2d0cc | 2603 | |
4038c495 GB |
2604 | v1 = CONSTRUCTOR_ELTS (t1); |
2605 | v2 = CONSTRUCTOR_ELTS (t2); | |
2606 | if (VEC_length (constructor_elt, v1) | |
2607 | != VEC_length (constructor_elt, v2)) | |
2608 | return 0; | |
2609 | ||
2610 | for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx) | |
08f2586c | 2611 | { |
4038c495 GB |
2612 | constructor_elt *c1 = VEC_index (constructor_elt, v1, idx); |
2613 | constructor_elt *c2 = VEC_index (constructor_elt, v2, idx); | |
2614 | ||
08f2586c | 2615 | /* Check that each value is the same... */ |
4038c495 | 2616 | if (!compare_constant (c1->value, c2->value)) |
08f2586c NS |
2617 | return 0; |
2618 | /* ... and that they apply to the same fields! */ | |
2619 | if (typecode == ARRAY_TYPE) | |
2620 | { | |
4038c495 | 2621 | if (!compare_constant (c1->index, c2->index)) |
08f2586c NS |
2622 | return 0; |
2623 | } | |
2624 | else | |
2625 | { | |
4038c495 | 2626 | if (c1->index != c2->index) |
08f2586c NS |
2627 | return 0; |
2628 | } | |
2629 | } | |
083cad55 | 2630 | |
4038c495 | 2631 | return 1; |
08f2586c | 2632 | } |
77fa0940 | 2633 | |
a9d07d6e | 2634 | case ADDR_EXPR: |
5d056e9b | 2635 | case FDESC_EXPR: |
a9d07d6e | 2636 | { |
e2500fed | 2637 | struct addr_const value1, value2; |
a9d07d6e | 2638 | |
e2500fed GK |
2639 | decode_addr_const (t1, &value1); |
2640 | decode_addr_const (t2, &value2); | |
2641 | return (value1.offset == value2.offset | |
2642 | && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0); | |
a9d07d6e | 2643 | } |
a9d07d6e RK |
2644 | |
2645 | case PLUS_EXPR: | |
2646 | case MINUS_EXPR: | |
fa212801 | 2647 | case RANGE_EXPR: |
e2500fed GK |
2648 | return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)) |
2649 | && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1))); | |
a9d07d6e RK |
2650 | |
2651 | case NOP_EXPR: | |
2652 | case CONVERT_EXPR: | |
2653 | case NON_LVALUE_EXPR: | |
a3d71605 | 2654 | case VIEW_CONVERT_EXPR: |
e2500fed | 2655 | return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); |
e9a25f70 JL |
2656 | |
2657 | default: | |
ac79cd5a | 2658 | { |
e2500fed | 2659 | tree nt1, nt2; |
ae2bcd98 RS |
2660 | nt1 = lang_hooks.expand_constant (t1); |
2661 | nt2 = lang_hooks.expand_constant (t2); | |
e2500fed GK |
2662 | if (nt1 != t1 || nt2 != t2) |
2663 | return compare_constant (nt1, nt2); | |
ac79cd5a RK |
2664 | else |
2665 | return 0; | |
2666 | } | |
79e68feb RS |
2667 | } |
2668 | ||
fbc848cc | 2669 | gcc_unreachable (); |
79e68feb RS |
2670 | } |
2671 | \f | |
e2500fed GK |
2672 | /* Make a copy of the whole tree structure for a constant. This |
2673 | handles the same types of nodes that compare_constant handles. */ | |
d12516f1 RS |
2674 | |
2675 | static tree | |
2e1eedd6 | 2676 | copy_constant (tree exp) |
d12516f1 RS |
2677 | { |
2678 | switch (TREE_CODE (exp)) | |
2679 | { | |
310bbbf4 JW |
2680 | case ADDR_EXPR: |
2681 | /* For ADDR_EXPR, we do not want to copy the decl whose address | |
2682 | is requested. We do want to copy constants though. */ | |
6615c446 | 2683 | if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0))) |
310bbbf4 JW |
2684 | return build1 (TREE_CODE (exp), TREE_TYPE (exp), |
2685 | copy_constant (TREE_OPERAND (exp, 0))); | |
2686 | else | |
2687 | return copy_node (exp); | |
2688 | ||
d12516f1 RS |
2689 | case INTEGER_CST: |
2690 | case REAL_CST: | |
2691 | case STRING_CST: | |
d12516f1 RS |
2692 | return copy_node (exp); |
2693 | ||
2694 | case COMPLEX_CST: | |
28eb1cb8 RK |
2695 | return build_complex (TREE_TYPE (exp), |
2696 | copy_constant (TREE_REALPART (exp)), | |
d12516f1 RS |
2697 | copy_constant (TREE_IMAGPART (exp))); |
2698 | ||
2699 | case PLUS_EXPR: | |
2700 | case MINUS_EXPR: | |
3244e67d RS |
2701 | return build2 (TREE_CODE (exp), TREE_TYPE (exp), |
2702 | copy_constant (TREE_OPERAND (exp, 0)), | |
2703 | copy_constant (TREE_OPERAND (exp, 1))); | |
d12516f1 RS |
2704 | |
2705 | case NOP_EXPR: | |
2706 | case CONVERT_EXPR: | |
a9d07d6e | 2707 | case NON_LVALUE_EXPR: |
a71c8ddc | 2708 | case VIEW_CONVERT_EXPR: |
d12516f1 RS |
2709 | return build1 (TREE_CODE (exp), TREE_TYPE (exp), |
2710 | copy_constant (TREE_OPERAND (exp, 0))); | |
2711 | ||
2712 | case CONSTRUCTOR: | |
2713 | { | |
2714 | tree copy = copy_node (exp); | |
4038c495 GB |
2715 | VEC(constructor_elt, gc) *v; |
2716 | unsigned HOST_WIDE_INT idx; | |
2717 | tree purpose, value; | |
083cad55 | 2718 | |
4038c495 GB |
2719 | v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt, |
2720 | CONSTRUCTOR_ELTS (exp))); | |
2721 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value) | |
2722 | { | |
2723 | constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL); | |
2724 | ce->index = purpose; | |
2725 | ce->value = copy_constant (value); | |
2726 | } | |
2727 | CONSTRUCTOR_ELTS (copy) = v; | |
d12516f1 RS |
2728 | return copy; |
2729 | } | |
2730 | ||
2731 | default: | |
e2500fed | 2732 | { |
fbc848cc | 2733 | tree t = lang_hooks.expand_constant (exp); |
083cad55 | 2734 | |
fbc848cc NS |
2735 | gcc_assert (t == exp); |
2736 | return copy_constant (t); | |
e2500fed | 2737 | } |
d12516f1 RS |
2738 | } |
2739 | } | |
ff8f4401 | 2740 | \f |
aacd3885 RS |
2741 | /* Return the alignment of constant EXP in bits. */ |
2742 | ||
2743 | static unsigned int | |
2744 | get_constant_alignment (tree exp) | |
2745 | { | |
2746 | unsigned int align; | |
2747 | ||
2748 | align = TYPE_ALIGN (TREE_TYPE (exp)); | |
2749 | #ifdef CONSTANT_ALIGNMENT | |
2750 | align = CONSTANT_ALIGNMENT (exp, align); | |
2751 | #endif | |
2752 | return align; | |
2753 | } | |
2754 | ||
2755 | /* Return the section into which constant EXP should be placed. */ | |
2756 | ||
2757 | static section * | |
2758 | get_constant_section (tree exp) | |
2759 | { | |
2760 | if (IN_NAMED_SECTION (exp)) | |
2761 | return get_named_section (exp, NULL, compute_reloc_for_constant (exp)); | |
2762 | else | |
2763 | return targetm.asm_out.select_section (exp, | |
2764 | compute_reloc_for_constant (exp), | |
2765 | get_constant_alignment (exp)); | |
2766 | } | |
2767 | ||
2768 | /* Return the size of constant EXP in bytes. */ | |
2769 | ||
2770 | static HOST_WIDE_INT | |
2771 | get_constant_size (tree exp) | |
2772 | { | |
2773 | HOST_WIDE_INT size; | |
2774 | ||
2775 | size = int_size_in_bytes (TREE_TYPE (exp)); | |
2776 | if (TREE_CODE (exp) == STRING_CST) | |
2777 | size = MAX (TREE_STRING_LENGTH (exp), size); | |
2778 | return size; | |
2779 | } | |
2780 | ||
293107d1 ZW |
2781 | /* Subroutine of output_constant_def: |
2782 | No constant equal to EXP is known to have been output. | |
2783 | Make a constant descriptor to enter EXP in the hash table. | |
2784 | Assign the label number and construct RTL to refer to the | |
2785 | constant's location in memory. | |
2786 | Caller is responsible for updating the hash table. */ | |
2787 | ||
2788 | static struct constant_descriptor_tree * | |
2e1eedd6 | 2789 | build_constant_desc (tree exp) |
293107d1 ZW |
2790 | { |
2791 | rtx symbol; | |
2792 | rtx rtl; | |
2793 | char label[256]; | |
2794 | int labelno; | |
2795 | struct constant_descriptor_tree *desc; | |
2796 | ||
2797 | desc = ggc_alloc (sizeof (*desc)); | |
3521b33c | 2798 | desc->value = copy_constant (exp); |
293107d1 | 2799 | |
9cf737f8 | 2800 | /* Propagate marked-ness to copied constant. */ |
6de9cd9a DN |
2801 | if (flag_mudflap && mf_marked_p (exp)) |
2802 | mf_mark (desc->value); | |
2803 | ||
293107d1 ZW |
2804 | /* Create a string containing the label name, in LABEL. */ |
2805 | labelno = const_labelno++; | |
2806 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno); | |
2807 | ||
2808 | /* We have a symbol name; construct the SYMBOL_REF and the MEM. */ | |
aacd3885 RS |
2809 | if (use_object_blocks_p ()) |
2810 | { | |
2811 | section *sect = get_constant_section (exp); | |
2812 | symbol = create_block_symbol (ggc_strdup (label), | |
2813 | get_block_for_section (sect), -1); | |
2814 | } | |
2815 | else | |
2816 | symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)); | |
2817 | SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL; | |
929e5e5b | 2818 | SET_SYMBOL_REF_DECL (symbol, desc->value); |
2adb9af1 | 2819 | TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1; |
293107d1 ZW |
2820 | |
2821 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol); | |
2822 | set_mem_attributes (rtl, exp, 1); | |
2823 | set_mem_alias_set (rtl, 0); | |
2824 | set_mem_alias_set (rtl, const_alias_set); | |
2825 | ||
2826 | /* Set flags or add text to the name to record information, such as | |
2827 | that it is a local symbol. If the name is changed, the macro | |
2828 | ASM_OUTPUT_LABELREF will have to know how to strip this | |
10b6a274 ZW |
2829 | information. This call might invalidate our local variable |
2830 | SYMBOL; we can't use it afterward. */ | |
2831 | ||
5fd9b178 | 2832 | targetm.encode_section_info (exp, rtl, true); |
293107d1 ZW |
2833 | |
2834 | desc->rtl = rtl; | |
293107d1 ZW |
2835 | |
2836 | return desc; | |
2837 | } | |
2838 | ||
79e68feb RS |
2839 | /* Return an rtx representing a reference to constant data in memory |
2840 | for the constant expression EXP. | |
ff8f4401 | 2841 | |
79e68feb RS |
2842 | If assembler code for such a constant has already been output, |
2843 | return an rtx to refer to it. | |
b20cbca2 | 2844 | Otherwise, output such a constant in memory |
ff8f4401 RS |
2845 | and generate an rtx for it. |
2846 | ||
10b6a274 ZW |
2847 | If DEFER is nonzero, this constant can be deferred and output only |
2848 | if referenced in the function after all optimizations. | |
bd7cf17e | 2849 | |
5e9295fa | 2850 | `const_desc_table' records which constants already have label strings. */ |
79e68feb RS |
2851 | |
2852 | rtx | |
2e1eedd6 | 2853 | output_constant_def (tree exp, int defer) |
79e68feb | 2854 | { |
e2500fed | 2855 | struct constant_descriptor_tree *desc; |
10b6a274 ZW |
2856 | struct constant_descriptor_tree key; |
2857 | void **loc; | |
79e68feb | 2858 | |
10b6a274 ZW |
2859 | /* Look up EXP in the table of constant descriptors. If we didn't find |
2860 | it, create a new one. */ | |
2861 | key.value = exp; | |
b96917bf JJ |
2862 | key.hash = const_hash_1 (exp); |
2863 | loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT); | |
46f9491e | 2864 | |
10b6a274 | 2865 | desc = *loc; |
14a774a9 | 2866 | if (desc == 0) |
00f07fb9 | 2867 | { |
293107d1 | 2868 | desc = build_constant_desc (exp); |
b96917bf | 2869 | desc->hash = key.hash; |
10b6a274 | 2870 | *loc = desc; |
14a774a9 RK |
2871 | } |
2872 | ||
10b6a274 | 2873 | maybe_output_constant_def_contents (desc, defer); |
293107d1 ZW |
2874 | return desc->rtl; |
2875 | } | |
79e68feb | 2876 | |
10b6a274 ZW |
2877 | /* Subroutine of output_constant_def: Decide whether or not we need to |
2878 | output the constant DESC now, and if so, do it. */ | |
293107d1 | 2879 | static void |
2e1eedd6 AJ |
2880 | maybe_output_constant_def_contents (struct constant_descriptor_tree *desc, |
2881 | int defer) | |
293107d1 | 2882 | { |
10b6a274 | 2883 | rtx symbol = XEXP (desc->rtl, 0); |
2adb9af1 | 2884 | tree exp = desc->value; |
10b6a274 | 2885 | |
293107d1 ZW |
2886 | if (flag_syntax_only) |
2887 | return; | |
79e68feb | 2888 | |
2adb9af1 | 2889 | if (TREE_ASM_WRITTEN (exp)) |
10b6a274 ZW |
2890 | /* Already output; don't do it again. */ |
2891 | return; | |
2892 | ||
3521b33c ZW |
2893 | /* We can always defer constants as long as the context allows |
2894 | doing so. */ | |
2895 | if (defer) | |
bd7cf17e | 2896 | { |
2adb9af1 RH |
2897 | /* Increment n_deferred_constants if it exists. It needs to be at |
2898 | least as large as the number of constants actually referred to | |
2899 | by the function. If it's too small we'll stop looking too early | |
2900 | and fail to emit constants; if it's too large we'll only look | |
2901 | through the entire function when we could have stopped earlier. */ | |
10b6a274 ZW |
2902 | if (cfun) |
2903 | n_deferred_constants++; | |
32a61907 | 2904 | return; |
ff8f4401 RS |
2905 | } |
2906 | ||
10b6a274 | 2907 | output_constant_def_contents (symbol); |
ff8f4401 RS |
2908 | } |
2909 | ||
aacd3885 RS |
2910 | /* Subroutine of output_constant_def_contents. Output the definition |
2911 | of constant EXP, which is pointed to by label LABEL. ALIGN is the | |
2912 | constant's alignment in bits. */ | |
2913 | ||
2914 | static void | |
2915 | assemble_constant_contents (tree exp, const char *label, unsigned int align) | |
2916 | { | |
2917 | HOST_WIDE_INT size; | |
2918 | ||
2919 | size = get_constant_size (exp); | |
2920 | ||
2921 | /* Do any machine/system dependent processing of the constant. */ | |
2922 | #ifdef ASM_DECLARE_CONSTANT_NAME | |
2923 | ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size); | |
2924 | #else | |
2925 | /* Standard thing is just output label for the constant. */ | |
2926 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
2927 | #endif /* ASM_DECLARE_CONSTANT_NAME */ | |
2928 | ||
2929 | /* Output the value of EXP. */ | |
2930 | output_constant (exp, size, align); | |
2931 | } | |
2932 | ||
10b6a274 | 2933 | /* We must output the constant data referred to by SYMBOL; do so. */ |
79e68feb | 2934 | |
ff8f4401 | 2935 | static void |
2e1eedd6 | 2936 | output_constant_def_contents (rtx symbol) |
ff8f4401 | 2937 | { |
10b6a274 | 2938 | tree exp = SYMBOL_REF_DECL (symbol); |
aacd3885 | 2939 | unsigned int align; |
10b6a274 | 2940 | |
293107d1 ZW |
2941 | /* Make sure any other constants whose addresses appear in EXP |
2942 | are assigned label numbers. */ | |
b2218cc1 AO |
2943 | output_addressed_constants (exp); |
2944 | ||
10b6a274 | 2945 | /* We are no longer deferring this constant. */ |
2adb9af1 | 2946 | TREE_ASM_WRITTEN (exp) = 1; |
10b6a274 | 2947 | |
aacd3885 RS |
2948 | /* If the constant is part of an object block, make sure that the |
2949 | decl has been positioned within its block, but do not write out | |
2950 | its definition yet. output_object_blocks will do that later. */ | |
3fa9c136 | 2951 | if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol)) |
aacd3885 | 2952 | place_block_symbol (symbol); |
8a425a05 | 2953 | else |
91ea4f8d | 2954 | { |
aacd3885 RS |
2955 | switch_to_section (get_constant_section (exp)); |
2956 | align = get_constant_alignment (exp); | |
2957 | if (align > BITS_PER_UNIT) | |
2958 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
2959 | assemble_constant_contents (exp, XSTR (symbol, 0), align); | |
91ea4f8d | 2960 | } |
6de9cd9a DN |
2961 | if (flag_mudflap) |
2962 | mudflap_enqueue_constant (exp); | |
a2a6a79b | 2963 | } |
75c20980 RH |
2964 | |
2965 | /* Look up EXP in the table of constant descriptors. Return the rtl | |
2966 | if it has been emitted, else null. */ | |
2967 | ||
2968 | rtx | |
2969 | lookup_constant_def (tree exp) | |
2970 | { | |
2971 | struct constant_descriptor_tree *desc; | |
2972 | struct constant_descriptor_tree key; | |
2973 | ||
2974 | key.value = exp; | |
b96917bf JJ |
2975 | key.hash = const_hash_1 (exp); |
2976 | desc = htab_find_with_hash (const_desc_htab, &key, key.hash); | |
75c20980 RH |
2977 | |
2978 | return (desc ? desc->rtl : NULL_RTX); | |
2979 | } | |
79e68feb | 2980 | \f |
e2500fed GK |
2981 | /* Used in the hash tables to avoid outputting the same constant |
2982 | twice. Unlike 'struct constant_descriptor_tree', RTX constants | |
3234b52d RH |
2983 | are output once per function, not once per file. */ |
2984 | /* ??? Only a few targets need per-function constant pools. Most | |
2985 | can use one per-file pool. Should add a targetm bit to tell the | |
2986 | difference. */ | |
2987 | ||
2988 | struct rtx_constant_pool GTY(()) | |
2989 | { | |
2990 | /* Pointers to first and last constant in pool, as ordered by offset. */ | |
2991 | struct constant_descriptor_rtx *first; | |
2992 | struct constant_descriptor_rtx *last; | |
2993 | ||
2994 | /* Hash facility for making memory-constants from constant rtl-expressions. | |
2995 | It is used on RISC machines where immediate integer arguments and | |
2996 | constant addresses are restricted so that such constants must be stored | |
2997 | in memory. */ | |
2998 | htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab; | |
3234b52d RH |
2999 | |
3000 | /* Current offset in constant pool (does not include any | |
3001 | machine-specific header). */ | |
3002 | HOST_WIDE_INT offset; | |
e2500fed GK |
3003 | }; |
3004 | ||
3234b52d | 3005 | struct constant_descriptor_rtx GTY((chain_next ("%h.next"))) |
79e68feb | 3006 | { |
3234b52d RH |
3007 | struct constant_descriptor_rtx *next; |
3008 | rtx mem; | |
3009 | rtx sym; | |
79e68feb | 3010 | rtx constant; |
3234b52d RH |
3011 | HOST_WIDE_INT offset; |
3012 | hashval_t hash; | |
94b01be3 | 3013 | enum machine_mode mode; |
a79e3a45 | 3014 | unsigned int align; |
3234b52d | 3015 | int labelno; |
91674c37 | 3016 | int mark; |
79e68feb RS |
3017 | }; |
3018 | ||
3234b52d | 3019 | /* Hash and compare functions for const_rtx_htab. */ |
79e68feb | 3020 | |
3234b52d RH |
3021 | static hashval_t |
3022 | const_desc_rtx_hash (const void *ptr) | |
3023 | { | |
3024 | const struct constant_descriptor_rtx *desc = ptr; | |
3025 | return desc->hash; | |
3026 | } | |
79e68feb | 3027 | |
3234b52d RH |
3028 | static int |
3029 | const_desc_rtx_eq (const void *a, const void *b) | |
79e68feb | 3030 | { |
3234b52d RH |
3031 | const struct constant_descriptor_rtx *x = a; |
3032 | const struct constant_descriptor_rtx *y = b; | |
3033 | ||
3034 | if (x->mode != y->mode) | |
3035 | return 0; | |
3036 | return rtx_equal_p (x->constant, y->constant); | |
57632c51 | 3037 | } |
79e68feb | 3038 | |
3234b52d | 3039 | /* This is the worker function for const_rtx_hash, called via for_each_rtx. */ |
46b33600 | 3040 | |
3234b52d RH |
3041 | static int |
3042 | const_rtx_hash_1 (rtx *xp, void *data) | |
3043 | { | |
3044 | unsigned HOST_WIDE_INT hwi; | |
3045 | enum machine_mode mode; | |
3046 | enum rtx_code code; | |
3047 | hashval_t h, *hp; | |
3048 | rtx x; | |
46b33600 | 3049 | |
3234b52d RH |
3050 | x = *xp; |
3051 | code = GET_CODE (x); | |
3052 | mode = GET_MODE (x); | |
3053 | h = (hashval_t) code * 1048573 + mode; | |
79e68feb | 3054 | |
3234b52d RH |
3055 | switch (code) |
3056 | { | |
3057 | case CONST_INT: | |
3058 | hwi = INTVAL (x); | |
3059 | fold_hwi: | |
69ef87e2 | 3060 | { |
3234b52d RH |
3061 | const int shift = sizeof (hashval_t) * CHAR_BIT; |
3062 | const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t); | |
3063 | int i; | |
69ef87e2 | 3064 | |
3234b52d RH |
3065 | h ^= (hashval_t) hwi; |
3066 | for (i = 1; i < n; ++i) | |
46b33600 | 3067 | { |
3234b52d RH |
3068 | hwi >>= shift; |
3069 | h ^= (hashval_t) hwi; | |
69ef87e2 AH |
3070 | } |
3071 | } | |
3072 | break; | |
3073 | ||
3234b52d RH |
3074 | case CONST_DOUBLE: |
3075 | if (mode == VOIDmode) | |
3076 | { | |
3077 | hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x); | |
3078 | goto fold_hwi; | |
3079 | } | |
3080 | else | |
3081 | h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x)); | |
79e68feb RS |
3082 | break; |
3083 | ||
237f420b RH |
3084 | case CONST_VECTOR: |
3085 | { | |
3086 | int i; | |
3087 | for (i = XVECLEN (x, 0); i-- > 0; ) | |
3088 | h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data); | |
3089 | } | |
3090 | break; | |
3091 | ||
79e68feb | 3092 | case SYMBOL_REF: |
3234b52d RH |
3093 | h ^= htab_hash_string (XSTR (x, 0)); |
3094 | break; | |
3095 | ||
79e68feb | 3096 | case LABEL_REF: |
3234b52d | 3097 | h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0)); |
79e68feb RS |
3098 | break; |
3099 | ||
3234b52d RH |
3100 | case UNSPEC: |
3101 | case UNSPEC_VOLATILE: | |
3102 | h = h * 251 + XINT (x, 1); | |
79e68feb RS |
3103 | break; |
3104 | ||
3105 | default: | |
fdf473ae | 3106 | break; |
79e68feb RS |
3107 | } |
3108 | ||
3234b52d RH |
3109 | hp = data; |
3110 | *hp = *hp * 509 + h; | |
3111 | return 0; | |
79e68feb RS |
3112 | } |
3113 | ||
3234b52d | 3114 | /* Compute a hash value for X, which should be a constant. */ |
57632c51 | 3115 | |
3234b52d RH |
3116 | static hashval_t |
3117 | const_rtx_hash (rtx x) | |
57632c51 | 3118 | { |
3234b52d RH |
3119 | hashval_t h = 0; |
3120 | for_each_rtx (&x, const_rtx_hash_1, &h); | |
3121 | return h; | |
57632c51 RS |
3122 | } |
3123 | ||
3234b52d RH |
3124 | \f |
3125 | /* Initialize constant pool hashing for a new function. */ | |
79e68feb | 3126 | |
3234b52d RH |
3127 | void |
3128 | init_varasm_status (struct function *f) | |
79e68feb | 3129 | { |
3234b52d RH |
3130 | struct varasm_status *p; |
3131 | struct rtx_constant_pool *pool; | |
79e68feb | 3132 | |
3234b52d RH |
3133 | p = ggc_alloc (sizeof (struct varasm_status)); |
3134 | f->varasm = p; | |
79e68feb | 3135 | |
3234b52d RH |
3136 | pool = ggc_alloc (sizeof (struct rtx_constant_pool)); |
3137 | p->pool = pool; | |
3138 | p->deferred_constants = 0; | |
79e68feb | 3139 | |
3234b52d RH |
3140 | pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash, |
3141 | const_desc_rtx_eq, NULL); | |
3234b52d RH |
3142 | pool->first = pool->last = NULL; |
3143 | pool->offset = 0; | |
79e68feb | 3144 | } |
3234b52d RH |
3145 | \f |
3146 | /* Given a MINUS expression, simplify it if both sides | |
3147 | include the same symbol. */ | |
79e68feb | 3148 | |
3234b52d RH |
3149 | rtx |
3150 | simplify_subtraction (rtx x) | |
79e68feb | 3151 | { |
3234b52d RH |
3152 | rtx r = simplify_rtx (x); |
3153 | return r ? r : x; | |
79e68feb RS |
3154 | } |
3155 | \f | |
3156 | /* Given a constant rtx X, make (or find) a memory constant for its value | |
3157 | and return a MEM rtx to refer to it in memory. */ | |
3158 | ||
3159 | rtx | |
2e1eedd6 | 3160 | force_const_mem (enum machine_mode mode, rtx x) |
79e68feb | 3161 | { |
3234b52d RH |
3162 | struct constant_descriptor_rtx *desc, tmp; |
3163 | struct rtx_constant_pool *pool = cfun->varasm->pool; | |
79e68feb | 3164 | char label[256]; |
52859c77 | 3165 | rtx def, symbol; |
3234b52d | 3166 | hashval_t hash; |
a79e3a45 | 3167 | unsigned int align; |
3234b52d | 3168 | void **slot; |
79e68feb | 3169 | |
3a04ff64 | 3170 | /* If we're not allowed to drop X into the constant pool, don't. */ |
5fd9b178 | 3171 | if (targetm.cannot_force_const_mem (x)) |
3a04ff64 RH |
3172 | return NULL_RTX; |
3173 | ||
3234b52d RH |
3174 | /* Lookup the value in the hashtable. */ |
3175 | tmp.constant = x; | |
3176 | tmp.mode = mode; | |
3177 | hash = const_rtx_hash (x); | |
3178 | slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT); | |
3179 | desc = *slot; | |
083cad55 | 3180 | |
3234b52d RH |
3181 | /* If the constant was already present, return its memory. */ |
3182 | if (desc) | |
3183 | return copy_rtx (desc->mem); | |
3184 | ||
3185 | /* Otherwise, create a new descriptor. */ | |
3186 | desc = ggc_alloc (sizeof (*desc)); | |
3187 | *slot = desc; | |
c26fbbca | 3188 | |
a79e3a45 RK |
3189 | /* Align the location counter as required by EXP's data type. */ |
3190 | align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode); | |
e5e8a8bf | 3191 | #ifdef CONSTANT_ALIGNMENT |
1063147c | 3192 | { |
ae2bcd98 | 3193 | tree type = lang_hooks.types.type_for_mode (mode, 0); |
1063147c RS |
3194 | if (type != NULL_TREE) |
3195 | align = CONSTANT_ALIGNMENT (make_tree (type, x), align); | |
3196 | } | |
e5e8a8bf | 3197 | #endif |
79e68feb | 3198 | |
3234b52d RH |
3199 | pool->offset += (align / BITS_PER_UNIT) - 1; |
3200 | pool->offset &= ~ ((align / BITS_PER_UNIT) - 1); | |
3201 | ||
3202 | desc->next = NULL; | |
3203 | desc->constant = tmp.constant; | |
3204 | desc->offset = pool->offset; | |
3205 | desc->hash = hash; | |
3206 | desc->mode = mode; | |
3207 | desc->align = align; | |
3208 | desc->labelno = const_labelno; | |
3209 | desc->mark = 0; | |
3210 | ||
3211 | pool->offset += GET_MODE_SIZE (mode); | |
3212 | if (pool->last) | |
3213 | pool->last->next = desc; | |
a79e3a45 | 3214 | else |
3234b52d RH |
3215 | pool->first = pool->last = desc; |
3216 | pool->last = desc; | |
79e68feb | 3217 | |
a79e3a45 RK |
3218 | /* Create a string containing the label name, in LABEL. */ |
3219 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
a79e3a45 | 3220 | ++const_labelno; |
79e68feb | 3221 | |
3234b52d RH |
3222 | /* Construct the SYMBOL_REF. Make sure to mark it as belonging to |
3223 | the constants pool. */ | |
aacd3885 RS |
3224 | if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x)) |
3225 | { | |
3226 | section *sect = targetm.asm_out.select_rtx_section (mode, x, align); | |
3227 | symbol = create_block_symbol (ggc_strdup (label), | |
3228 | get_block_for_section (sect), -1); | |
3229 | } | |
3230 | else | |
3231 | symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)); | |
3232 | desc->sym = symbol; | |
3233 | SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL; | |
3234b52d | 3234 | CONSTANT_POOL_ADDRESS_P (symbol) = 1; |
929e5e5b | 3235 | SET_SYMBOL_REF_CONSTANT (symbol, desc); |
3234b52d RH |
3236 | current_function_uses_const_pool = 1; |
3237 | ||
3234b52d | 3238 | /* Construct the MEM. */ |
542a8afa | 3239 | desc->mem = def = gen_const_mem (mode, symbol); |
ae2bcd98 | 3240 | set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1); |
d5606ec9 | 3241 | set_mem_align (def, align); |
289c5b45 | 3242 | |
3234b52d RH |
3243 | /* If we're dropping a label to the constant pool, make sure we |
3244 | don't delete it. */ | |
3245 | if (GET_CODE (x) == LABEL_REF) | |
3246 | LABEL_PRESERVE_P (XEXP (x, 0)) = 1; | |
79e68feb | 3247 | |
21e9fc47 | 3248 | return copy_rtx (def); |
79e68feb RS |
3249 | } |
3250 | \f | |
79e68feb RS |
3251 | /* Given a constant pool SYMBOL_REF, return the corresponding constant. */ |
3252 | ||
3253 | rtx | |
2e1eedd6 | 3254 | get_pool_constant (rtx addr) |
79e68feb | 3255 | { |
c185c797 | 3256 | return SYMBOL_REF_CONSTANT (addr)->constant; |
36edd3cc BS |
3257 | } |
3258 | ||
149d6f9e JJ |
3259 | /* Given a constant pool SYMBOL_REF, return the corresponding constant |
3260 | and whether it has been output or not. */ | |
3261 | ||
3262 | rtx | |
2e1eedd6 | 3263 | get_pool_constant_mark (rtx addr, bool *pmarked) |
149d6f9e | 3264 | { |
3234b52d RH |
3265 | struct constant_descriptor_rtx *desc; |
3266 | ||
c185c797 | 3267 | desc = SYMBOL_REF_CONSTANT (addr); |
3234b52d RH |
3268 | *pmarked = (desc->mark != 0); |
3269 | return desc->constant; | |
149d6f9e JJ |
3270 | } |
3271 | ||
79e68feb RS |
3272 | /* Similar, return the mode. */ |
3273 | ||
3274 | enum machine_mode | |
2e1eedd6 | 3275 | get_pool_mode (rtx addr) |
79e68feb | 3276 | { |
c185c797 | 3277 | return SYMBOL_REF_CONSTANT (addr)->mode; |
36edd3cc BS |
3278 | } |
3279 | ||
79e68feb RS |
3280 | /* Return the size of the constant pool. */ |
3281 | ||
3282 | int | |
2e1eedd6 | 3283 | get_pool_size (void) |
79e68feb | 3284 | { |
3234b52d | 3285 | return cfun->varasm->pool->offset; |
79e68feb RS |
3286 | } |
3287 | \f | |
3234b52d RH |
3288 | /* Worker function for output_constant_pool_1. Emit assembly for X |
3289 | in MODE with known alignment ALIGN. */ | |
79e68feb | 3290 | |
3234b52d RH |
3291 | static void |
3292 | output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align) | |
79e68feb | 3293 | { |
3234b52d | 3294 | switch (GET_MODE_CLASS (mode)) |
79e68feb | 3295 | { |
3234b52d | 3296 | case MODE_FLOAT: |
15ed7b52 | 3297 | case MODE_DECIMAL_FLOAT: |
fbc848cc NS |
3298 | { |
3299 | REAL_VALUE_TYPE r; | |
083cad55 | 3300 | |
fbc848cc NS |
3301 | gcc_assert (GET_CODE (x) == CONST_DOUBLE); |
3302 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
3303 | assemble_real (r, mode, align); | |
3304 | break; | |
3305 | } | |
083cad55 | 3306 | |
3234b52d RH |
3307 | case MODE_INT: |
3308 | case MODE_PARTIAL_INT: | |
3309 | assemble_integer (x, GET_MODE_SIZE (mode), align, 1); | |
3310 | break; | |
79e68feb | 3311 | |
3234b52d RH |
3312 | case MODE_VECTOR_FLOAT: |
3313 | case MODE_VECTOR_INT: | |
3314 | { | |
3315 | int i, units; | |
3316 | enum machine_mode submode = GET_MODE_INNER (mode); | |
3317 | unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode)); | |
79e68feb | 3318 | |
fbc848cc | 3319 | gcc_assert (GET_CODE (x) == CONST_VECTOR); |
3234b52d | 3320 | units = CONST_VECTOR_NUNITS (x); |
79e68feb | 3321 | |
3234b52d | 3322 | for (i = 0; i < units; i++) |
69ef87e2 | 3323 | { |
3234b52d RH |
3324 | rtx elt = CONST_VECTOR_ELT (x, i); |
3325 | output_constant_pool_2 (submode, elt, i ? subalign : align); | |
69ef87e2 | 3326 | } |
3234b52d RH |
3327 | } |
3328 | break; | |
69ef87e2 | 3329 | |
3234b52d | 3330 | default: |
fbc848cc | 3331 | gcc_unreachable (); |
3234b52d RH |
3332 | } |
3333 | } | |
69ef87e2 | 3334 | |
aacd3885 RS |
3335 | /* Worker function for output_constant_pool. Emit constant DESC, |
3336 | giving it ALIGN bits of alignment. */ | |
69ef87e2 | 3337 | |
3234b52d | 3338 | static void |
aacd3885 RS |
3339 | output_constant_pool_1 (struct constant_descriptor_rtx *desc, |
3340 | unsigned int align) | |
3234b52d RH |
3341 | { |
3342 | rtx x, tmp; | |
69ef87e2 | 3343 | |
3234b52d RH |
3344 | x = desc->constant; |
3345 | ||
3346 | /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF) | |
3347 | whose CODE_LABEL has been deleted. This can occur if a jump table | |
3348 | is eliminated by optimization. If so, write a constant of zero | |
3349 | instead. Note that this can also happen by turning the | |
3350 | CODE_LABEL into a NOTE. */ | |
3351 | /* ??? This seems completely and utterly wrong. Certainly it's | |
3352 | not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper | |
3353 | functioning even with INSN_DELETED_P and friends. */ | |
3354 | ||
3355 | tmp = x; | |
3356 | switch (GET_CODE (x)) | |
3357 | { | |
3358 | case CONST: | |
3359 | if (GET_CODE (XEXP (x, 0)) != PLUS | |
3360 | || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF) | |
3361 | break; | |
3362 | tmp = XEXP (XEXP (x, 0), 0); | |
3363 | /* FALLTHRU */ | |
69ef87e2 | 3364 | |
3234b52d RH |
3365 | case LABEL_REF: |
3366 | tmp = XEXP (x, 0); | |
fbc848cc NS |
3367 | gcc_assert (!INSN_DELETED_P (tmp)); |
3368 | gcc_assert (!NOTE_P (tmp) | |
3369 | || NOTE_LINE_NUMBER (tmp) != NOTE_INSN_DELETED); | |
3234b52d | 3370 | break; |
79e68feb | 3371 | |
3234b52d RH |
3372 | default: |
3373 | break; | |
3374 | } | |
3375 | ||
29a82058 | 3376 | #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY |
3234b52d | 3377 | ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode, |
aacd3885 | 3378 | align, desc->labelno, done); |
29a82058 | 3379 | #endif |
7f83c0e7 | 3380 | |
aacd3885 | 3381 | assemble_align (align); |
5c8c0abd | 3382 | |
3234b52d | 3383 | /* Output the label. */ |
5fd9b178 | 3384 | targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno); |
91674c37 | 3385 | |
3234b52d | 3386 | /* Output the data. */ |
aacd3885 | 3387 | output_constant_pool_2 (desc->mode, x, align); |
91674c37 | 3388 | |
3234b52d RH |
3389 | /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS |
3390 | sections have proper size. */ | |
aacd3885 | 3391 | if (align > GET_MODE_BITSIZE (desc->mode) |
d6b5193b RS |
3392 | && in_section |
3393 | && (in_section->common.flags & SECTION_MERGE)) | |
aacd3885 | 3394 | assemble_align (align); |
91674c37 | 3395 | |
3234b52d RH |
3396 | #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY |
3397 | done: | |
3398 | #endif | |
3399 | return; | |
3400 | } | |
91674c37 | 3401 | |
3234b52d RH |
3402 | /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers |
3403 | to as used. Emit referenced deferred strings. This function can | |
3404 | be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */ | |
d2ce9169 | 3405 | |
3234b52d RH |
3406 | static int |
3407 | mark_constant (rtx *current_rtx, void *data) | |
3408 | { | |
3409 | struct rtx_constant_pool *pool = data; | |
3410 | rtx x = *current_rtx; | |
91674c37 | 3411 | |
3234b52d RH |
3412 | if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF) |
3413 | return 0; | |
afdfb380 | 3414 | |
3234b52d RH |
3415 | if (CONSTANT_POOL_ADDRESS_P (x)) |
3416 | { | |
c185c797 | 3417 | struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x); |
3234b52d RH |
3418 | if (desc->mark == 0) |
3419 | { | |
3420 | desc->mark = 1; | |
3421 | for_each_rtx (&desc->constant, mark_constant, pool); | |
3422 | } | |
afdfb380 | 3423 | } |
3234b52d RH |
3424 | else if (TREE_CONSTANT_POOL_ADDRESS_P (x)) |
3425 | { | |
3426 | tree exp = SYMBOL_REF_DECL (x); | |
3427 | if (!TREE_ASM_WRITTEN (exp)) | |
3428 | { | |
3429 | n_deferred_constants--; | |
3430 | output_constant_def_contents (x); | |
3431 | } | |
3432 | } | |
3433 | ||
3434 | return -1; | |
083cad55 | 3435 | } |
91674c37 | 3436 | |
3234b52d | 3437 | /* Look through appropriate parts of INSN, marking all entries in the |
fcbd8ef2 JO |
3438 | constant pool which are actually being used. Entries that are only |
3439 | referenced by other constants are also marked as used. Emit | |
3440 | deferred strings that are used. */ | |
3441 | ||
91674c37 | 3442 | static void |
3234b52d | 3443 | mark_constants (struct rtx_constant_pool *pool, rtx insn) |
91674c37 | 3444 | { |
3234b52d | 3445 | if (!INSN_P (insn)) |
91674c37 ILT |
3446 | return; |
3447 | ||
91674c37 ILT |
3448 | /* Insns may appear inside a SEQUENCE. Only check the patterns of |
3449 | insns, not any notes that may be attached. We don't want to mark | |
3450 | a constant just because it happens to appear in a REG_EQUIV note. */ | |
3234b52d | 3451 | if (GET_CODE (PATTERN (insn)) == SEQUENCE) |
91674c37 | 3452 | { |
3234b52d RH |
3453 | rtx seq = PATTERN (insn); |
3454 | int i, n = XVECLEN (seq, 0); | |
3455 | for (i = 0; i < n; ++i) | |
3456 | { | |
3457 | rtx subinsn = XVECEXP (seq, 0, i); | |
3458 | if (INSN_P (subinsn)) | |
3459 | for_each_rtx (&PATTERN (subinsn), mark_constant, pool); | |
3460 | } | |
91674c37 | 3461 | } |
3234b52d RH |
3462 | else |
3463 | for_each_rtx (&PATTERN (insn), mark_constant, pool); | |
3464 | } | |
91674c37 | 3465 | |
3234b52d RH |
3466 | /* Look through the instructions for this function, and mark all the |
3467 | entries in POOL which are actually being used. Emit deferred constants | |
3468 | which have indeed been used. */ | |
91674c37 | 3469 | |
3234b52d RH |
3470 | static void |
3471 | mark_constant_pool (struct rtx_constant_pool *pool) | |
3472 | { | |
3473 | rtx insn, link; | |
91674c37 | 3474 | |
3234b52d RH |
3475 | if (pool->first == 0 && n_deferred_constants == 0) |
3476 | return; | |
91674c37 | 3477 | |
3234b52d RH |
3478 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
3479 | mark_constants (pool, insn); | |
91674c37 | 3480 | |
3234b52d RH |
3481 | for (link = current_function_epilogue_delay_list; |
3482 | link; | |
3483 | link = XEXP (link, 1)) | |
3484 | mark_constants (pool, XEXP (link, 0)); | |
91674c37 | 3485 | } |
fcbd8ef2 | 3486 | |
3234b52d | 3487 | /* Write all the constants in the constant pool. */ |
fcbd8ef2 | 3488 | |
3234b52d RH |
3489 | void |
3490 | output_constant_pool (const char *fnname ATTRIBUTE_UNUSED, | |
3491 | tree fndecl ATTRIBUTE_UNUSED) | |
fcbd8ef2 | 3492 | { |
3234b52d RH |
3493 | struct rtx_constant_pool *pool = cfun->varasm->pool; |
3494 | struct constant_descriptor_rtx *desc; | |
fcbd8ef2 | 3495 | |
3234b52d RH |
3496 | /* It is possible for gcc to call force_const_mem and then to later |
3497 | discard the instructions which refer to the constant. In such a | |
3498 | case we do not need to output the constant. */ | |
3499 | mark_constant_pool (pool); | |
a79e3a45 | 3500 | |
3234b52d RH |
3501 | #ifdef ASM_OUTPUT_POOL_PROLOGUE |
3502 | ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset); | |
3503 | #endif | |
3504 | ||
3505 | for (desc = pool->first; desc ; desc = desc->next) | |
aacd3885 RS |
3506 | if (desc->mark) |
3507 | { | |
3508 | /* If the constant is part of an object_block, make sure that | |
3509 | the constant has been positioned within its block, but do not | |
3510 | write out its definition yet. output_object_blocks will do | |
3511 | that later. */ | |
3fa9c136 RS |
3512 | if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym) |
3513 | && SYMBOL_REF_BLOCK (desc->sym)) | |
aacd3885 RS |
3514 | place_block_symbol (desc->sym); |
3515 | else | |
3516 | { | |
3517 | switch_to_section (targetm.asm_out.select_rtx_section | |
3518 | (desc->mode, desc->constant, desc->align)); | |
3519 | output_constant_pool_1 (desc, desc->align); | |
3520 | } | |
3521 | } | |
3234b52d RH |
3522 | |
3523 | #ifdef ASM_OUTPUT_POOL_EPILOGUE | |
3524 | ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset); | |
3525 | #endif | |
fcbd8ef2 | 3526 | } |
79e68feb | 3527 | \f |
b2218cc1 | 3528 | /* Determine what kind of relocations EXP may need. */ |
79e68feb | 3529 | |
b2218cc1 AO |
3530 | int |
3531 | compute_reloc_for_constant (tree exp) | |
79e68feb | 3532 | { |
7eca317a | 3533 | int reloc = 0, reloc2; |
ac79cd5a | 3534 | tree tem; |
79e68feb | 3535 | |
c165f94f CC |
3536 | /* Give the front-end a chance to convert VALUE to something that |
3537 | looks more like a constant to the back-end. */ | |
ae2bcd98 | 3538 | exp = lang_hooks.expand_constant (exp); |
c165f94f | 3539 | |
79e68feb RS |
3540 | switch (TREE_CODE (exp)) |
3541 | { | |
3542 | case ADDR_EXPR: | |
5d056e9b | 3543 | case FDESC_EXPR: |
ac79cd5a RK |
3544 | /* Go inside any operations that get_inner_reference can handle and see |
3545 | if what's inside is a constant: no need to do anything here for | |
3546 | addresses of variables or functions. */ | |
3547 | for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem); | |
3548 | tem = TREE_OPERAND (tem, 0)) | |
3549 | ; | |
79e68feb | 3550 | |
d2c35e67 JH |
3551 | if (TREE_PUBLIC (tem)) |
3552 | reloc |= 2; | |
3553 | else | |
3554 | reloc |= 1; | |
79e68feb RS |
3555 | break; |
3556 | ||
3557 | case PLUS_EXPR: | |
b2218cc1 AO |
3558 | reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0)); |
3559 | reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1)); | |
79e68feb RS |
3560 | break; |
3561 | ||
7eca317a | 3562 | case MINUS_EXPR: |
b2218cc1 AO |
3563 | reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0)); |
3564 | reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1)); | |
7eca317a JJ |
3565 | /* The difference of two local labels is computable at link time. */ |
3566 | if (reloc == 1 && reloc2 == 1) | |
3567 | reloc = 0; | |
3568 | else | |
3569 | reloc |= reloc2; | |
3570 | break; | |
3571 | ||
79e68feb RS |
3572 | case NOP_EXPR: |
3573 | case CONVERT_EXPR: | |
37a52112 | 3574 | case NON_LVALUE_EXPR: |
0d26b2ff | 3575 | case VIEW_CONVERT_EXPR: |
b2218cc1 | 3576 | reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0)); |
79e68feb RS |
3577 | break; |
3578 | ||
3579 | case CONSTRUCTOR: | |
4038c495 GB |
3580 | { |
3581 | unsigned HOST_WIDE_INT idx; | |
3582 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem) | |
3583 | if (tem != 0) | |
3584 | reloc |= compute_reloc_for_constant (tem); | |
3585 | } | |
79e68feb RS |
3586 | break; |
3587 | ||
e9a25f70 | 3588 | default: |
79e68feb RS |
3589 | break; |
3590 | } | |
3591 | return reloc; | |
3592 | } | |
b2218cc1 AO |
3593 | |
3594 | /* Find all the constants whose addresses are referenced inside of EXP, | |
3595 | and make sure assembler code with a label has been output for each one. | |
3596 | Indicate whether an ADDR_EXPR has been encountered. */ | |
3597 | ||
3598 | static void | |
3599 | output_addressed_constants (tree exp) | |
3600 | { | |
3601 | tree tem; | |
3602 | ||
3603 | /* Give the front-end a chance to convert VALUE to something that | |
3604 | looks more like a constant to the back-end. */ | |
ae2bcd98 | 3605 | exp = lang_hooks.expand_constant (exp); |
b2218cc1 AO |
3606 | |
3607 | switch (TREE_CODE (exp)) | |
3608 | { | |
3609 | case ADDR_EXPR: | |
3610 | case FDESC_EXPR: | |
3611 | /* Go inside any operations that get_inner_reference can handle and see | |
3612 | if what's inside is a constant: no need to do anything here for | |
3613 | addresses of variables or functions. */ | |
3614 | for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem); | |
3615 | tem = TREE_OPERAND (tem, 0)) | |
3616 | ; | |
3617 | ||
2256aa1c ZL |
3618 | /* If we have an initialized CONST_DECL, retrieve the initializer. */ |
3619 | if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem)) | |
3620 | tem = DECL_INITIAL (tem); | |
3621 | ||
6615c446 | 3622 | if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR) |
b2218cc1 AO |
3623 | output_constant_def (tem, 0); |
3624 | break; | |
3625 | ||
3626 | case PLUS_EXPR: | |
3627 | case MINUS_EXPR: | |
3628 | output_addressed_constants (TREE_OPERAND (exp, 1)); | |
3629 | /* Fall through. */ | |
3630 | ||
3631 | case NOP_EXPR: | |
3632 | case CONVERT_EXPR: | |
3633 | case NON_LVALUE_EXPR: | |
0d26b2ff | 3634 | case VIEW_CONVERT_EXPR: |
b2218cc1 AO |
3635 | output_addressed_constants (TREE_OPERAND (exp, 0)); |
3636 | break; | |
3637 | ||
3638 | case CONSTRUCTOR: | |
4038c495 GB |
3639 | { |
3640 | unsigned HOST_WIDE_INT idx; | |
3641 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem) | |
3642 | if (tem != 0) | |
3643 | output_addressed_constants (tem); | |
3644 | } | |
b2218cc1 AO |
3645 | break; |
3646 | ||
3647 | default: | |
3648 | break; | |
3649 | } | |
3650 | } | |
79e68feb | 3651 | \f |
14a774a9 RK |
3652 | /* Return nonzero if VALUE is a valid constant-valued expression |
3653 | for use in initializing a static variable; one that can be an | |
3654 | element of a "constant" initializer. | |
3655 | ||
3656 | Return null_pointer_node if the value is absolute; | |
3657 | if it is relocatable, return the variable that determines the relocation. | |
3658 | We assume that VALUE has been folded as much as possible; | |
3659 | therefore, we do not need to check for such things as | |
3660 | arithmetic-combinations of integers. */ | |
3661 | ||
3662 | tree | |
2e1eedd6 | 3663 | initializer_constant_valid_p (tree value, tree endtype) |
14a774a9 | 3664 | { |
99740276 MM |
3665 | /* Give the front-end a chance to convert VALUE to something that |
3666 | looks more like a constant to the back-end. */ | |
ae2bcd98 | 3667 | value = lang_hooks.expand_constant (value); |
99740276 | 3668 | |
14a774a9 RK |
3669 | switch (TREE_CODE (value)) |
3670 | { | |
3671 | case CONSTRUCTOR: | |
3672 | if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE | |
3673 | || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE) | |
3674 | && TREE_CONSTANT (value) | |
4038c495 | 3675 | && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (value))) |
cf9ad9a7 | 3676 | { |
4038c495 | 3677 | unsigned HOST_WIDE_INT idx; |
cf9ad9a7 MM |
3678 | tree elt; |
3679 | bool absolute = true; | |
3680 | ||
4038c495 | 3681 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt) |
cf9ad9a7 MM |
3682 | { |
3683 | tree reloc; | |
4038c495 | 3684 | reloc = initializer_constant_valid_p (elt, TREE_TYPE (elt)); |
cf9ad9a7 MM |
3685 | if (!reloc) |
3686 | return NULL_TREE; | |
3687 | if (reloc != null_pointer_node) | |
3688 | absolute = false; | |
3689 | } | |
3690 | /* For a non-absolute relocation, there is no single | |
3691 | variable that can be "the variable that determines the | |
3692 | relocation." */ | |
3693 | return absolute ? null_pointer_node : error_mark_node; | |
3694 | } | |
46f9491e | 3695 | |
cf9ad9a7 | 3696 | return TREE_STATIC (value) ? null_pointer_node : NULL_TREE; |
14a774a9 RK |
3697 | |
3698 | case INTEGER_CST: | |
69ef87e2 | 3699 | case VECTOR_CST: |
14a774a9 RK |
3700 | case REAL_CST: |
3701 | case STRING_CST: | |
3702 | case COMPLEX_CST: | |
3703 | return null_pointer_node; | |
3704 | ||
3705 | case ADDR_EXPR: | |
67231816 | 3706 | case FDESC_EXPR: |
5cc200fc | 3707 | value = staticp (TREE_OPERAND (value, 0)); |
125f2a50 MM |
3708 | if (value) |
3709 | { | |
3710 | /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out to | |
3711 | be a constant, this is old-skool offsetof-like nonsense. */ | |
3712 | if (TREE_CODE (value) == INDIRECT_REF | |
3713 | && TREE_CONSTANT (TREE_OPERAND (value, 0))) | |
3714 | return null_pointer_node; | |
3715 | /* Taking the address of a nested function involves a trampoline. */ | |
3716 | if (TREE_CODE (value) == FUNCTION_DECL | |
083cad55 | 3717 | && ((decl_function_context (value) |
125f2a50 MM |
3718 | && !DECL_NO_STATIC_CHAIN (value)) |
3719 | || DECL_DLLIMPORT_P (value))) | |
3720 | return NULL_TREE; | |
3721 | /* "&{...}" requires a temporary to hold the constructed | |
3722 | object. */ | |
3723 | if (TREE_CODE (value) == CONSTRUCTOR) | |
3724 | return NULL_TREE; | |
3725 | } | |
5cc200fc | 3726 | return value; |
14a774a9 | 3727 | |
ed239f5a | 3728 | case VIEW_CONVERT_EXPR: |
14a774a9 RK |
3729 | case NON_LVALUE_EXPR: |
3730 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); | |
3731 | ||
3732 | case CONVERT_EXPR: | |
3733 | case NOP_EXPR: | |
9560cbde MM |
3734 | { |
3735 | tree src; | |
3736 | tree src_type; | |
3737 | tree dest_type; | |
3738 | ||
3739 | src = TREE_OPERAND (value, 0); | |
3740 | src_type = TREE_TYPE (src); | |
3741 | dest_type = TREE_TYPE (value); | |
3742 | ||
3743 | /* Allow conversions between pointer types, floating-point | |
3744 | types, and offset types. */ | |
3745 | if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)) | |
3746 | || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type)) | |
3747 | || (TREE_CODE (dest_type) == OFFSET_TYPE | |
3748 | && TREE_CODE (src_type) == OFFSET_TYPE)) | |
3749 | return initializer_constant_valid_p (src, endtype); | |
3750 | ||
3751 | /* Allow length-preserving conversions between integer types. */ | |
3752 | if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type) | |
3753 | && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type))) | |
3754 | return initializer_constant_valid_p (src, endtype); | |
3755 | ||
3756 | /* Allow conversions between other integer types only if | |
3757 | explicit value. */ | |
3758 | if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)) | |
3759 | { | |
3760 | tree inner = initializer_constant_valid_p (src, endtype); | |
3761 | if (inner == null_pointer_node) | |
3762 | return null_pointer_node; | |
3763 | break; | |
3764 | } | |
14a774a9 | 3765 | |
9560cbde MM |
3766 | /* Allow (int) &foo provided int is as wide as a pointer. */ |
3767 | if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type) | |
3768 | && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))) | |
3769 | return initializer_constant_valid_p (src, endtype); | |
3770 | ||
3771 | /* Likewise conversions from int to pointers, but also allow | |
3772 | conversions from 0. */ | |
3773 | if ((POINTER_TYPE_P (dest_type) | |
3774 | || TREE_CODE (dest_type) == OFFSET_TYPE) | |
3775 | && INTEGRAL_TYPE_P (src_type)) | |
3776 | { | |
971dfb9b DD |
3777 | if (TREE_CODE (src) == INTEGER_CST |
3778 | && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)) | |
3779 | return null_pointer_node; | |
9560cbde MM |
3780 | if (integer_zerop (src)) |
3781 | return null_pointer_node; | |
3782 | else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)) | |
3783 | return initializer_constant_valid_p (src, endtype); | |
3784 | } | |
14a774a9 | 3785 | |
9560cbde MM |
3786 | /* Allow conversions to struct or union types if the value |
3787 | inside is okay. */ | |
3788 | if (TREE_CODE (dest_type) == RECORD_TYPE | |
3789 | || TREE_CODE (dest_type) == UNION_TYPE) | |
3790 | return initializer_constant_valid_p (src, endtype); | |
3791 | } | |
14a774a9 RK |
3792 | break; |
3793 | ||
3794 | case PLUS_EXPR: | |
3795 | if (! INTEGRAL_TYPE_P (endtype) | |
3796 | || TYPE_PRECISION (endtype) >= POINTER_SIZE) | |
c26fbbca | 3797 | { |
14a774a9 RK |
3798 | tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), |
3799 | endtype); | |
3800 | tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), | |
3801 | endtype); | |
3802 | /* If either term is absolute, use the other terms relocation. */ | |
3803 | if (valid0 == null_pointer_node) | |
3804 | return valid1; | |
3805 | if (valid1 == null_pointer_node) | |
3806 | return valid0; | |
c26fbbca | 3807 | } |
14a774a9 RK |
3808 | break; |
3809 | ||
3810 | case MINUS_EXPR: | |
3811 | if (! INTEGRAL_TYPE_P (endtype) | |
3812 | || TYPE_PRECISION (endtype) >= POINTER_SIZE) | |
3813 | { | |
3814 | tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), | |
3815 | endtype); | |
3816 | tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), | |
3817 | endtype); | |
3818 | /* Win if second argument is absolute. */ | |
3819 | if (valid1 == null_pointer_node) | |
3820 | return valid0; | |
3821 | /* Win if both arguments have the same relocation. | |
3822 | Then the value is absolute. */ | |
3823 | if (valid0 == valid1 && valid0 != 0) | |
3824 | return null_pointer_node; | |
212addfa JO |
3825 | |
3826 | /* Since GCC guarantees that string constants are unique in the | |
3827 | generated code, a subtraction between two copies of the same | |
3828 | constant string is absolute. */ | |
5cc200fc RH |
3829 | if (valid0 && TREE_CODE (valid0) == STRING_CST |
3830 | && valid1 && TREE_CODE (valid1) == STRING_CST | |
3831 | && operand_equal_p (valid0, valid1, 1)) | |
212addfa | 3832 | return null_pointer_node; |
14a774a9 RK |
3833 | } |
3834 | ||
5cc200fc | 3835 | /* Support narrowing differences. */ |
14a774a9 RK |
3836 | if (INTEGRAL_TYPE_P (endtype)) |
3837 | { | |
3838 | tree op0, op1; | |
5cc200fc | 3839 | |
14a774a9 RK |
3840 | op0 = TREE_OPERAND (value, 0); |
3841 | op1 = TREE_OPERAND (value, 1); | |
fdf473ae RH |
3842 | |
3843 | /* Like STRIP_NOPS except allow the operand mode to widen. | |
14b493d6 | 3844 | This works around a feature of fold that simplifies |
fdf473ae RH |
3845 | (int)(p1 - p2) to ((int)p1 - (int)p2) under the theory |
3846 | that the narrower operation is cheaper. */ | |
3847 | ||
3848 | while (TREE_CODE (op0) == NOP_EXPR | |
3849 | || TREE_CODE (op0) == CONVERT_EXPR | |
3850 | || TREE_CODE (op0) == NON_LVALUE_EXPR) | |
3851 | { | |
3852 | tree inner = TREE_OPERAND (op0, 0); | |
3853 | if (inner == error_mark_node | |
3854 | || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) | |
3855 | || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0))) | |
3856 | > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner))))) | |
3857 | break; | |
3858 | op0 = inner; | |
3859 | } | |
3860 | ||
3861 | while (TREE_CODE (op1) == NOP_EXPR | |
3862 | || TREE_CODE (op1) == CONVERT_EXPR | |
3863 | || TREE_CODE (op1) == NON_LVALUE_EXPR) | |
3864 | { | |
3865 | tree inner = TREE_OPERAND (op1, 0); | |
3866 | if (inner == error_mark_node | |
3867 | || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) | |
3868 | || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1))) | |
3869 | > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner))))) | |
3870 | break; | |
3871 | op1 = inner; | |
3872 | } | |
14a774a9 | 3873 | |
5cc200fc RH |
3874 | op0 = initializer_constant_valid_p (op0, endtype); |
3875 | op1 = initializer_constant_valid_p (op1, endtype); | |
3876 | ||
3877 | /* Both initializers must be known. */ | |
3878 | if (op0 && op1) | |
3879 | { | |
3880 | if (op0 == op1) | |
3881 | return null_pointer_node; | |
3882 | ||
3883 | /* Support differences between labels. */ | |
3884 | if (TREE_CODE (op0) == LABEL_DECL | |
3885 | && TREE_CODE (op1) == LABEL_DECL) | |
3886 | return null_pointer_node; | |
3887 | ||
3888 | if (TREE_CODE (op0) == STRING_CST | |
3889 | && TREE_CODE (op1) == STRING_CST | |
3890 | && operand_equal_p (op0, op1, 1)) | |
3891 | return null_pointer_node; | |
3892 | } | |
14a774a9 RK |
3893 | } |
3894 | break; | |
3895 | ||
3896 | default: | |
3897 | break; | |
3898 | } | |
3899 | ||
3900 | return 0; | |
3901 | } | |
3902 | \f | |
79e68feb RS |
3903 | /* Output assembler code for constant EXP to FILE, with no label. |
3904 | This includes the pseudo-op such as ".int" or ".byte", and a newline. | |
3905 | Assumes output_addressed_constants has been done on EXP already. | |
3906 | ||
3907 | Generate exactly SIZE bytes of assembler data, padding at the end | |
3908 | with zeros if necessary. SIZE must always be specified. | |
3909 | ||
3910 | SIZE is important for structure constructors, | |
3911 | since trailing members may have been omitted from the constructor. | |
3912 | It is also important for initialization of arrays from string constants | |
3913 | since the full length of the string constant might not be wanted. | |
3914 | It is also needed for initialization of unions, where the initializer's | |
3915 | type is just one member, and that may not be as long as the union. | |
3916 | ||
3917 | There a case in which we would fail to output exactly SIZE bytes: | |
3918 | for a structure constructor that wants to produce more than SIZE bytes. | |
c8af3574 RH |
3919 | But such constructors will never be generated for any possible input. |
3920 | ||
3921 | ALIGN is the alignment of the data in bits. */ | |
79e68feb RS |
3922 | |
3923 | void | |
2e1eedd6 | 3924 | output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align) |
79e68feb | 3925 | { |
ac79cd5a | 3926 | enum tree_code code; |
58e15542 | 3927 | unsigned HOST_WIDE_INT thissize; |
79e68feb | 3928 | |
14b493d6 | 3929 | /* Some front-ends use constants other than the standard language-independent |
ed239f5a RK |
3930 | varieties, but which may still be output directly. Give the front-end a |
3931 | chance to convert EXP to a language-independent representation. */ | |
ae2bcd98 | 3932 | exp = lang_hooks.expand_constant (exp); |
e697e20a | 3933 | |
e9996db7 | 3934 | if (size == 0 || flag_syntax_only) |
79e68feb RS |
3935 | return; |
3936 | ||
57b51d4d | 3937 | /* See if we're trying to initialize a pointer in a non-default mode |
056061d8 DD |
3938 | to the address of some declaration somewhere. If the target says |
3939 | the mode is valid for pointers, assume the target has a way of | |
3940 | resolving it. */ | |
3941 | if (TREE_CODE (exp) == NOP_EXPR | |
3942 | && POINTER_TYPE_P (TREE_TYPE (exp)) | |
3943 | && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp)))) | |
3944 | { | |
3945 | tree saved_type = TREE_TYPE (exp); | |
3946 | ||
3947 | /* Peel off any intermediate conversions-to-pointer for valid | |
3948 | pointer modes. */ | |
3949 | while (TREE_CODE (exp) == NOP_EXPR | |
3950 | && POINTER_TYPE_P (TREE_TYPE (exp)) | |
3951 | && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp)))) | |
3952 | exp = TREE_OPERAND (exp, 0); | |
3953 | ||
3954 | /* If what we're left with is the address of something, we can | |
3955 | convert the address to the final type and output it that | |
3956 | way. */ | |
3957 | if (TREE_CODE (exp) == ADDR_EXPR) | |
3958 | exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0)); | |
971dfb9b DD |
3959 | /* Likewise for constant ints. */ |
3960 | else if (TREE_CODE (exp) == INTEGER_CST) | |
3961 | exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp), | |
3962 | TREE_INT_CST_HIGH (exp)); | |
3963 | ||
056061d8 DD |
3964 | } |
3965 | ||
ac79cd5a RK |
3966 | /* Eliminate any conversions since we'll be outputting the underlying |
3967 | constant. */ | |
3968 | while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR | |
ed239f5a RK |
3969 | || TREE_CODE (exp) == NON_LVALUE_EXPR |
3970 | || TREE_CODE (exp) == VIEW_CONVERT_EXPR) | |
056061d8 DD |
3971 | { |
3972 | HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp)); | |
3973 | HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0))); | |
3974 | ||
69fcfd68 | 3975 | /* Make sure eliminating the conversion is really a no-op, except with |
f7952e0a EB |
3976 | VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and |
3977 | union types to allow for Ada unchecked unions. */ | |
e2953e41 | 3978 | if (type_size > op_size |
f7952e0a EB |
3979 | && TREE_CODE (exp) != VIEW_CONVERT_EXPR |
3980 | && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE) | |
056061d8 DD |
3981 | internal_error ("no-op convert from %wd to %wd bytes in initializer", |
3982 | op_size, type_size); | |
3983 | ||
3984 | exp = TREE_OPERAND (exp, 0); | |
3985 | } | |
ac79cd5a RK |
3986 | |
3987 | code = TREE_CODE (TREE_TYPE (exp)); | |
3988 | thissize = int_size_in_bytes (TREE_TYPE (exp)); | |
be1ad04c | 3989 | |
fff9e713 MT |
3990 | /* Allow a constructor with no elements for any data type. |
3991 | This means to fill the space with zeros. */ | |
4038c495 GB |
3992 | if (TREE_CODE (exp) == CONSTRUCTOR |
3993 | && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp))) | |
fff9e713 | 3994 | { |
b93a436e | 3995 | assemble_zeros (size); |
fff9e713 MT |
3996 | return; |
3997 | } | |
3998 | ||
67231816 RH |
3999 | if (TREE_CODE (exp) == FDESC_EXPR) |
4000 | { | |
f42f3c2d | 4001 | #ifdef ASM_OUTPUT_FDESC |
67231816 RH |
4002 | HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0); |
4003 | tree decl = TREE_OPERAND (exp, 0); | |
67231816 RH |
4004 | ASM_OUTPUT_FDESC (asm_out_file, decl, part); |
4005 | #else | |
fbc848cc | 4006 | gcc_unreachable (); |
67231816 RH |
4007 | #endif |
4008 | return; | |
4009 | } | |
4010 | ||
ac79cd5a | 4011 | /* Now output the underlying data. If we've handling the padding, return. |
42048866 | 4012 | Otherwise, break and ensure SIZE is the size written. */ |
79e68feb RS |
4013 | switch (code) |
4014 | { | |
644ea577 | 4015 | case BOOLEAN_TYPE: |
79e68feb RS |
4016 | case INTEGER_TYPE: |
4017 | case ENUMERAL_TYPE: | |
4018 | case POINTER_TYPE: | |
4019 | case REFERENCE_TYPE: | |
a5ac359a | 4020 | case OFFSET_TYPE: |
37366632 | 4021 | if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode, |
79e68feb | 4022 | EXPAND_INITIALIZER), |
42048866 | 4023 | MIN (size, thissize), align, 0)) |
79e68feb | 4024 | error ("initializer for integer value is too complicated"); |
79e68feb RS |
4025 | break; |
4026 | ||
4027 | case REAL_TYPE: | |
4028 | if (TREE_CODE (exp) != REAL_CST) | |
4029 | error ("initializer for floating value is not a floating constant"); | |
4030 | ||
02befdf4 | 4031 | assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align); |
79e68feb RS |
4032 | break; |
4033 | ||
4034 | case COMPLEX_TYPE: | |
ac79cd5a RK |
4035 | output_constant (TREE_REALPART (exp), thissize / 2, align); |
4036 | output_constant (TREE_IMAGPART (exp), thissize / 2, | |
4037 | min_align (align, BITS_PER_UNIT * (thissize / 2))); | |
79e68feb RS |
4038 | break; |
4039 | ||
4040 | case ARRAY_TYPE: | |
e6834654 | 4041 | case VECTOR_TYPE: |
fbc848cc | 4042 | switch (TREE_CODE (exp)) |
79e68feb | 4043 | { |
fbc848cc | 4044 | case CONSTRUCTOR: |
c8af3574 | 4045 | output_constructor (exp, size, align); |
79e68feb | 4046 | return; |
fbc848cc | 4047 | case STRING_CST: |
58e15542 JH |
4048 | thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp), |
4049 | size); | |
ac79cd5a | 4050 | assemble_string (TREE_STRING_POINTER (exp), thissize); |
fbc848cc | 4051 | break; |
d744e06e | 4052 | |
fbc848cc NS |
4053 | case VECTOR_CST: |
4054 | { | |
4055 | int elt_size; | |
4056 | tree link; | |
4057 | unsigned int nalign; | |
4058 | enum machine_mode inner; | |
083cad55 | 4059 | |
fbc848cc NS |
4060 | inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp))); |
4061 | nalign = MIN (align, GET_MODE_ALIGNMENT (inner)); | |
083cad55 | 4062 | |
fbc848cc | 4063 | elt_size = GET_MODE_SIZE (inner); |
083cad55 | 4064 | |
fbc848cc NS |
4065 | link = TREE_VECTOR_CST_ELTS (exp); |
4066 | output_constant (TREE_VALUE (link), elt_size, align); | |
4067 | while ((link = TREE_CHAIN (link)) != NULL) | |
4068 | output_constant (TREE_VALUE (link), elt_size, nalign); | |
4069 | break; | |
4070 | } | |
4071 | default: | |
4072 | gcc_unreachable (); | |
d744e06e | 4073 | } |
79e68feb RS |
4074 | break; |
4075 | ||
4076 | case RECORD_TYPE: | |
4077 | case UNION_TYPE: | |
fbc848cc NS |
4078 | gcc_assert (TREE_CODE (exp) == CONSTRUCTOR); |
4079 | output_constructor (exp, size, align); | |
79e68feb | 4080 | return; |
474bda6c | 4081 | |
0974a3b8 RK |
4082 | case ERROR_MARK: |
4083 | return; | |
4084 | ||
e9a25f70 | 4085 | default: |
fbc848cc | 4086 | gcc_unreachable (); |
79e68feb RS |
4087 | } |
4088 | ||
d3e0dffb JH |
4089 | if (size > thissize) |
4090 | assemble_zeros (size - thissize); | |
79e68feb | 4091 | } |
ca695ac9 | 4092 | |
79e68feb | 4093 | \f |
a25f1211 RH |
4094 | /* Subroutine of output_constructor, used for computing the size of |
4095 | arrays of unspecified length. VAL must be a CONSTRUCTOR of an array | |
4096 | type with an unspecified upper bound. */ | |
4097 | ||
ffc5c6a9 | 4098 | static unsigned HOST_WIDE_INT |
2e1eedd6 | 4099 | array_size_for_constructor (tree val) |
a25f1211 RH |
4100 | { |
4101 | tree max_index, i; | |
4038c495 GB |
4102 | unsigned HOST_WIDE_INT cnt; |
4103 | tree index, value; | |
a25f1211 | 4104 | |
ac79cd5a RK |
4105 | /* This code used to attempt to handle string constants that are not |
4106 | arrays of single-bytes, but nothing else does, so there's no point in | |
4107 | doing it here. */ | |
b6fc7110 | 4108 | if (TREE_CODE (val) == STRING_CST) |
ac79cd5a RK |
4109 | return TREE_STRING_LENGTH (val); |
4110 | ||
a25f1211 | 4111 | max_index = NULL_TREE; |
4038c495 | 4112 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value) |
a25f1211 | 4113 | { |
a25f1211 RH |
4114 | if (TREE_CODE (index) == RANGE_EXPR) |
4115 | index = TREE_OPERAND (index, 1); | |
4116 | if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index)) | |
4117 | max_index = index; | |
4118 | } | |
4119 | ||
a25f1211 | 4120 | if (max_index == NULL_TREE) |
ffc5c6a9 | 4121 | return 0; |
a25f1211 RH |
4122 | |
4123 | /* Compute the total number of array elements. */ | |
46f9491e | 4124 | i = size_binop (MINUS_EXPR, convert (sizetype, max_index), |
ffc5c6a9 RH |
4125 | convert (sizetype, |
4126 | TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val))))); | |
57decb7e | 4127 | i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1)); |
a25f1211 RH |
4128 | |
4129 | /* Multiply by the array element unit size to find number of bytes. */ | |
ffc5c6a9 | 4130 | i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val)))); |
a25f1211 RH |
4131 | |
4132 | return tree_low_cst (i, 1); | |
4133 | } | |
4134 | ||
4135 | /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants). | |
79e68feb RS |
4136 | Generate at least SIZE bytes, padding if necessary. */ |
4137 | ||
5a13eaa4 | 4138 | static void |
2e1eedd6 AJ |
4139 | output_constructor (tree exp, unsigned HOST_WIDE_INT size, |
4140 | unsigned int align) | |
79e68feb | 4141 | { |
85f3d674 | 4142 | tree type = TREE_TYPE (exp); |
4038c495 | 4143 | tree field = 0; |
85f3d674 | 4144 | tree min_index = 0; |
79e68feb RS |
4145 | /* Number of bytes output or skipped so far. |
4146 | In other words, current position within the constructor. */ | |
85f3d674 | 4147 | HOST_WIDE_INT total_bytes = 0; |
272d0bee | 4148 | /* Nonzero means BYTE contains part of a byte, to be output. */ |
79e68feb | 4149 | int byte_buffer_in_use = 0; |
b3694847 | 4150 | int byte = 0; |
4038c495 GB |
4151 | unsigned HOST_WIDE_INT cnt; |
4152 | constructor_elt *ce; | |
79e68feb | 4153 | |
fbc848cc | 4154 | gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT); |
79e68feb | 4155 | |
85f3d674 RK |
4156 | if (TREE_CODE (type) == RECORD_TYPE) |
4157 | field = TYPE_FIELDS (type); | |
79e68feb | 4158 | |
85f3d674 RK |
4159 | if (TREE_CODE (type) == ARRAY_TYPE |
4160 | && TYPE_DOMAIN (type) != 0) | |
4161 | min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type)); | |
13b457e7 | 4162 | |
79e68feb RS |
4163 | /* As LINK goes through the elements of the constant, |
4164 | FIELD goes through the structure fields, if the constant is a structure. | |
4165 | if the constant is a union, then we override this, | |
4166 | by getting the field from the TREE_LIST element. | |
43f7bed5 VM |
4167 | But the constant could also be an array. Then FIELD is zero. |
4168 | ||
4169 | There is always a maximum of one element in the chain LINK for unions | |
4170 | (even if the initializer in a source program incorrectly contains | |
2d76cb1a | 4171 | more one). */ |
4038c495 GB |
4172 | for (cnt = 0; |
4173 | VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce); | |
4174 | cnt++, field = field ? TREE_CHAIN (field) : 0) | |
79e68feb | 4175 | { |
4038c495 | 4176 | tree val = ce->value; |
3181cbfd RS |
4177 | tree index = 0; |
4178 | ||
85f3d674 RK |
4179 | /* The element in a union constructor specifies the proper field |
4180 | or index. */ | |
4181 | if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE | |
4182 | || TREE_CODE (type) == QUAL_UNION_TYPE) | |
4038c495 GB |
4183 | && ce->index != 0) |
4184 | field = ce->index; | |
3181cbfd | 4185 | |
85f3d674 | 4186 | else if (TREE_CODE (type) == ARRAY_TYPE) |
4038c495 | 4187 | index = ce->index; |
3181cbfd | 4188 | |
907393db | 4189 | #ifdef ASM_COMMENT_START |
bce988a2 AH |
4190 | if (field && flag_verbose_asm) |
4191 | fprintf (asm_out_file, "%s %s:\n", | |
083cad55 EC |
4192 | ASM_COMMENT_START, |
4193 | DECL_NAME (field) | |
bce988a2 AH |
4194 | ? IDENTIFIER_POINTER (DECL_NAME (field)) |
4195 | : "<anonymous>"); | |
907393db | 4196 | #endif |
bce988a2 | 4197 | |
79e68feb | 4198 | /* Eliminate the marker that makes a cast not be an lvalue. */ |
d964285c CH |
4199 | if (val != 0) |
4200 | STRIP_NOPS (val); | |
79e68feb | 4201 | |
8311a11f PB |
4202 | if (index && TREE_CODE (index) == RANGE_EXPR) |
4203 | { | |
bf1aaf0a | 4204 | unsigned HOST_WIDE_INT fieldsize |
85f3d674 RK |
4205 | = int_size_in_bytes (TREE_TYPE (type)); |
4206 | HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0); | |
4207 | HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0); | |
8311a11f | 4208 | HOST_WIDE_INT index; |
c8af3574 | 4209 | unsigned int align2 = min_align (align, fieldsize * BITS_PER_UNIT); |
85f3d674 | 4210 | |
8311a11f PB |
4211 | for (index = lo_index; index <= hi_index; index++) |
4212 | { | |
4213 | /* Output the element's initial value. */ | |
4214 | if (val == 0) | |
4215 | assemble_zeros (fieldsize); | |
4216 | else | |
c8af3574 | 4217 | output_constant (val, fieldsize, align2); |
8311a11f PB |
4218 | |
4219 | /* Count its size. */ | |
4220 | total_bytes += fieldsize; | |
4221 | } | |
4222 | } | |
4223 | else if (field == 0 || !DECL_BIT_FIELD (field)) | |
79e68feb | 4224 | { |
3181cbfd RS |
4225 | /* An element that is not a bit-field. */ |
4226 | ||
bf1aaf0a | 4227 | unsigned HOST_WIDE_INT fieldsize; |
79e68feb RS |
4228 | /* Since this structure is static, |
4229 | we know the positions are constant. */ | |
85f3d674 | 4230 | HOST_WIDE_INT pos = field ? int_byte_position (field) : 0; |
c8af3574 | 4231 | unsigned int align2; |
770ae6cc | 4232 | |
3181cbfd | 4233 | if (index != 0) |
85f3d674 RK |
4234 | pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1) |
4235 | * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0))); | |
79e68feb | 4236 | |
3181cbfd | 4237 | /* Output any buffered-up bit-fields preceding this element. */ |
79e68feb RS |
4238 | if (byte_buffer_in_use) |
4239 | { | |
eac50d7a | 4240 | assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1); |
79e68feb RS |
4241 | total_bytes++; |
4242 | byte_buffer_in_use = 0; | |
4243 | } | |
4244 | ||
4245 | /* Advance to offset of this element. | |
4246 | Note no alignment needed in an array, since that is guaranteed | |
4247 | if each element has the proper size. */ | |
85f3d674 | 4248 | if ((field != 0 || index != 0) && pos != total_bytes) |
79e68feb | 4249 | { |
4038c495 | 4250 | gcc_assert (pos >= total_bytes); |
85f3d674 RK |
4251 | assemble_zeros (pos - total_bytes); |
4252 | total_bytes = pos; | |
79e68feb | 4253 | } |
ca2eed21 | 4254 | |
c8af3574 RH |
4255 | /* Find the alignment of this element. */ |
4256 | align2 = min_align (align, BITS_PER_UNIT * pos); | |
46f9491e | 4257 | |
79e68feb RS |
4258 | /* Determine size this element should occupy. */ |
4259 | if (field) | |
a25f1211 | 4260 | { |
ffc5c6a9 RH |
4261 | fieldsize = 0; |
4262 | ||
4263 | /* If this is an array with an unspecified upper bound, | |
4264 | the initializer determines the size. */ | |
4265 | /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL, | |
4266 | but we cannot do this until the deprecated support for | |
4267 | initializing zero-length array members is removed. */ | |
4268 | if (TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE | |
4269 | && TYPE_DOMAIN (TREE_TYPE (field)) | |
4270 | && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (field)))) | |
4271 | { | |
a25f1211 | 4272 | fieldsize = array_size_for_constructor (val); |
ffc5c6a9 RH |
4273 | /* Given a non-empty initialization, this field had |
4274 | better be last. */ | |
fbc848cc | 4275 | gcc_assert (!fieldsize || !TREE_CHAIN (field)); |
ffc5c6a9 RH |
4276 | } |
4277 | else if (DECL_SIZE_UNIT (field)) | |
4278 | { | |
4279 | /* ??? This can't be right. If the decl size overflows | |
4280 | a host integer we will silently emit no data. */ | |
4281 | if (host_integerp (DECL_SIZE_UNIT (field), 1)) | |
4282 | fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1); | |
4283 | } | |
a25f1211 | 4284 | } |
79e68feb | 4285 | else |
85f3d674 | 4286 | fieldsize = int_size_in_bytes (TREE_TYPE (type)); |
79e68feb RS |
4287 | |
4288 | /* Output the element's initial value. */ | |
4289 | if (val == 0) | |
4290 | assemble_zeros (fieldsize); | |
4291 | else | |
c8af3574 | 4292 | output_constant (val, fieldsize, align2); |
79e68feb RS |
4293 | |
4294 | /* Count its size. */ | |
4295 | total_bytes += fieldsize; | |
4296 | } | |
4297 | else if (val != 0 && TREE_CODE (val) != INTEGER_CST) | |
971801ff | 4298 | error ("invalid initial value for member %qs", |
79e68feb RS |
4299 | IDENTIFIER_POINTER (DECL_NAME (field))); |
4300 | else | |
4301 | { | |
4302 | /* Element that is a bit-field. */ | |
4303 | ||
770ae6cc RK |
4304 | HOST_WIDE_INT next_offset = int_bit_position (field); |
4305 | HOST_WIDE_INT end_offset | |
4306 | = (next_offset + tree_low_cst (DECL_SIZE (field), 1)); | |
79e68feb RS |
4307 | |
4308 | if (val == 0) | |
4309 | val = integer_zero_node; | |
4310 | ||
4311 | /* If this field does not start in this (or, next) byte, | |
4312 | skip some bytes. */ | |
4313 | if (next_offset / BITS_PER_UNIT != total_bytes) | |
4314 | { | |
4315 | /* Output remnant of any bit field in previous bytes. */ | |
4316 | if (byte_buffer_in_use) | |
4317 | { | |
eac50d7a | 4318 | assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1); |
79e68feb RS |
4319 | total_bytes++; |
4320 | byte_buffer_in_use = 0; | |
4321 | } | |
4322 | ||
4323 | /* If still not at proper byte, advance to there. */ | |
4324 | if (next_offset / BITS_PER_UNIT != total_bytes) | |
4325 | { | |
4038c495 | 4326 | gcc_assert (next_offset / BITS_PER_UNIT >= total_bytes); |
79e68feb RS |
4327 | assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes); |
4328 | total_bytes = next_offset / BITS_PER_UNIT; | |
4329 | } | |
4330 | } | |
4331 | ||
4332 | if (! byte_buffer_in_use) | |
4333 | byte = 0; | |
4334 | ||
4335 | /* We must split the element into pieces that fall within | |
4336 | separate bytes, and combine each byte with previous or | |
4337 | following bit-fields. */ | |
4338 | ||
b4ac57ab | 4339 | /* next_offset is the offset n fbits from the beginning of |
79e68feb RS |
4340 | the structure to the next bit of this element to be processed. |
4341 | end_offset is the offset of the first bit past the end of | |
4342 | this element. */ | |
4343 | while (next_offset < end_offset) | |
4344 | { | |
4345 | int this_time; | |
e7105755 JW |
4346 | int shift; |
4347 | HOST_WIDE_INT value; | |
85f3d674 RK |
4348 | HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT; |
4349 | HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT; | |
79e68feb RS |
4350 | |
4351 | /* Advance from byte to byte | |
4352 | within this element when necessary. */ | |
4353 | while (next_byte != total_bytes) | |
4354 | { | |
eac50d7a | 4355 | assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1); |
79e68feb RS |
4356 | total_bytes++; |
4357 | byte = 0; | |
4358 | } | |
4359 | ||
4360 | /* Number of bits we can process at once | |
4361 | (all part of the same byte). */ | |
4362 | this_time = MIN (end_offset - next_offset, | |
4363 | BITS_PER_UNIT - next_bit); | |
f76b9db2 | 4364 | if (BYTES_BIG_ENDIAN) |
79e68feb | 4365 | { |
f76b9db2 ILT |
4366 | /* On big-endian machine, take the most significant bits |
4367 | first (of the bits that are significant) | |
4368 | and put them into bytes from the most significant end. */ | |
4369 | shift = end_offset - next_offset - this_time; | |
85f3d674 | 4370 | |
f76b9db2 | 4371 | /* Don't try to take a bunch of bits that cross |
dfb2c079 HB |
4372 | the word boundary in the INTEGER_CST. We can |
4373 | only select bits from the LOW or HIGH part | |
4374 | not from both. */ | |
f76b9db2 ILT |
4375 | if (shift < HOST_BITS_PER_WIDE_INT |
4376 | && shift + this_time > HOST_BITS_PER_WIDE_INT) | |
4377 | { | |
8b1cb95b GK |
4378 | this_time = shift + this_time - HOST_BITS_PER_WIDE_INT; |
4379 | shift = HOST_BITS_PER_WIDE_INT; | |
f76b9db2 ILT |
4380 | } |
4381 | ||
4382 | /* Now get the bits from the appropriate constant word. */ | |
4383 | if (shift < HOST_BITS_PER_WIDE_INT) | |
85f3d674 | 4384 | value = TREE_INT_CST_LOW (val); |
fbc848cc | 4385 | else |
f76b9db2 | 4386 | { |
fbc848cc | 4387 | gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT); |
f76b9db2 ILT |
4388 | value = TREE_INT_CST_HIGH (val); |
4389 | shift -= HOST_BITS_PER_WIDE_INT; | |
4390 | } | |
85f3d674 | 4391 | |
dfb2c079 HB |
4392 | /* Get the result. This works only when: |
4393 | 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ | |
f76b9db2 | 4394 | byte |= (((value >> shift) |
dfb2c079 | 4395 | & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) |
f76b9db2 | 4396 | << (BITS_PER_UNIT - this_time - next_bit)); |
79e68feb RS |
4397 | } |
4398 | else | |
79e68feb | 4399 | { |
f76b9db2 ILT |
4400 | /* On little-endian machines, |
4401 | take first the least significant bits of the value | |
4402 | and pack them starting at the least significant | |
4403 | bits of the bytes. */ | |
770ae6cc RK |
4404 | shift = next_offset - int_bit_position (field); |
4405 | ||
f76b9db2 | 4406 | /* Don't try to take a bunch of bits that cross |
dfb2c079 HB |
4407 | the word boundary in the INTEGER_CST. We can |
4408 | only select bits from the LOW or HIGH part | |
4409 | not from both. */ | |
f76b9db2 ILT |
4410 | if (shift < HOST_BITS_PER_WIDE_INT |
4411 | && shift + this_time > HOST_BITS_PER_WIDE_INT) | |
770ae6cc | 4412 | this_time = (HOST_BITS_PER_WIDE_INT - shift); |
f76b9db2 ILT |
4413 | |
4414 | /* Now get the bits from the appropriate constant word. */ | |
e9a25f70 | 4415 | if (shift < HOST_BITS_PER_WIDE_INT) |
f76b9db2 | 4416 | value = TREE_INT_CST_LOW (val); |
fbc848cc | 4417 | else |
f76b9db2 | 4418 | { |
fbc848cc | 4419 | gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT); |
f76b9db2 ILT |
4420 | value = TREE_INT_CST_HIGH (val); |
4421 | shift -= HOST_BITS_PER_WIDE_INT; | |
4422 | } | |
770ae6cc | 4423 | |
dfb2c079 HB |
4424 | /* Get the result. This works only when: |
4425 | 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ | |
f76b9db2 | 4426 | byte |= (((value >> shift) |
dfb2c079 | 4427 | & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) |
f76b9db2 | 4428 | << next_bit); |
79e68feb | 4429 | } |
85f3d674 | 4430 | |
79e68feb RS |
4431 | next_offset += this_time; |
4432 | byte_buffer_in_use = 1; | |
4433 | } | |
4434 | } | |
4435 | } | |
85f3d674 | 4436 | |
79e68feb RS |
4437 | if (byte_buffer_in_use) |
4438 | { | |
eac50d7a | 4439 | assemble_integer (GEN_INT (byte), 1, BITS_PER_UNIT, 1); |
79e68feb RS |
4440 | total_bytes++; |
4441 | } | |
85f3d674 | 4442 | |
58e15542 | 4443 | if ((unsigned HOST_WIDE_INT)total_bytes < size) |
79e68feb RS |
4444 | assemble_zeros (size - total_bytes); |
4445 | } | |
ca695ac9 | 4446 | |
ecb0eece | 4447 | /* This TREE_LIST contains any weak symbol declarations waiting |
46f9491e | 4448 | to be emitted. */ |
e2500fed | 4449 | static GTY(()) tree weak_decls; |
0e9264a2 | 4450 | |
f90bf7ca MM |
4451 | /* Mark DECL as weak. */ |
4452 | ||
4453 | static void | |
2e1eedd6 | 4454 | mark_weak (tree decl) |
f90bf7ca MM |
4455 | { |
4456 | DECL_WEAK (decl) = 1; | |
4457 | ||
4458 | if (DECL_RTL_SET_P (decl) | |
3c0cb5de | 4459 | && MEM_P (DECL_RTL (decl)) |
f90bf7ca MM |
4460 | && XEXP (DECL_RTL (decl), 0) |
4461 | && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF) | |
4462 | SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1; | |
4463 | } | |
41077ce4 | 4464 | |
45806a3f FS |
4465 | /* Merge weak status between NEWDECL and OLDDECL. */ |
4466 | ||
4467 | void | |
2e1eedd6 | 4468 | merge_weak (tree newdecl, tree olddecl) |
45806a3f | 4469 | { |
45806a3f | 4470 | if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl)) |
46fb43a7 JJ |
4471 | { |
4472 | if (DECL_WEAK (newdecl) && SUPPORTS_WEAK) | |
4473 | { | |
4474 | tree *pwd; | |
4475 | /* We put the NEWDECL on the weak_decls list at some point | |
4476 | and OLDDECL as well. Keep just OLDDECL on the list. */ | |
4477 | for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd)) | |
4478 | if (TREE_VALUE (*pwd) == newdecl) | |
4479 | { | |
4480 | *pwd = TREE_CHAIN (*pwd); | |
4481 | break; | |
4482 | } | |
4483 | } | |
4484 | return; | |
4485 | } | |
45806a3f | 4486 | |
f90bf7ca MM |
4487 | if (DECL_WEAK (newdecl)) |
4488 | { | |
4489 | tree wd; | |
41077ce4 | 4490 | |
f90bf7ca MM |
4491 | /* NEWDECL is weak, but OLDDECL is not. */ |
4492 | ||
4493 | /* If we already output the OLDDECL, we're in trouble; we can't | |
4494 | go back and make it weak. This error cannot caught in | |
4495 | declare_weak because the NEWDECL and OLDDECL was not yet | |
4496 | been merged; therefore, TREE_ASM_WRITTEN was not set. */ | |
14285ace | 4497 | if (TREE_ASM_WRITTEN (olddecl)) |
dee15844 JM |
4498 | error ("weak declaration of %q+D must precede definition", |
4499 | newdecl); | |
14285ace RH |
4500 | |
4501 | /* If we've already generated rtl referencing OLDDECL, we may | |
4502 | have done so in a way that will not function properly with | |
4503 | a weak symbol. */ | |
4504 | else if (TREE_USED (olddecl) | |
34fb9ba5 | 4505 | && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl))) |
dee15844 JM |
4506 | warning (0, "weak declaration of %q+D after first use results " |
4507 | "in unspecified behavior", newdecl); | |
14285ace | 4508 | |
f90bf7ca MM |
4509 | if (SUPPORTS_WEAK) |
4510 | { | |
4511 | /* We put the NEWDECL on the weak_decls list at some point. | |
4512 | Replace it with the OLDDECL. */ | |
4513 | for (wd = weak_decls; wd; wd = TREE_CHAIN (wd)) | |
4514 | if (TREE_VALUE (wd) == newdecl) | |
4515 | { | |
4516 | TREE_VALUE (wd) = olddecl; | |
4517 | break; | |
4518 | } | |
4519 | /* We may not find the entry on the list. If NEWDECL is a | |
4520 | weak alias, then we will have already called | |
4521 | globalize_decl to remove the entry; in that case, we do | |
4522 | not need to do anything. */ | |
4523 | } | |
45806a3f | 4524 | |
f90bf7ca MM |
4525 | /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */ |
4526 | mark_weak (olddecl); | |
4527 | } | |
4528 | else | |
4529 | /* OLDDECL was weak, but NEWDECL was not explicitly marked as | |
4530 | weak. Just update NEWDECL to indicate that it's weak too. */ | |
4531 | mark_weak (newdecl); | |
45806a3f FS |
4532 | } |
4533 | ||
4b8af8d9 JM |
4534 | /* Declare DECL to be a weak symbol. */ |
4535 | ||
4536 | void | |
2e1eedd6 | 4537 | declare_weak (tree decl) |
4b8af8d9 JM |
4538 | { |
4539 | if (! TREE_PUBLIC (decl)) | |
dee15844 | 4540 | error ("weak declaration of %q+D must be public", decl); |
45806a3f | 4541 | else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) |
dee15844 | 4542 | error ("weak declaration of %q+D must precede definition", decl); |
daefd78b | 4543 | else if (SUPPORTS_WEAK) |
ecb0eece RH |
4544 | { |
4545 | if (! DECL_WEAK (decl)) | |
4546 | weak_decls = tree_cons (NULL, decl, weak_decls); | |
4547 | } | |
4ae08f95 | 4548 | else |
dee15844 | 4549 | warning (0, "weak declaration of %q+D not supported", decl); |
4ae08f95 | 4550 | |
f90bf7ca | 4551 | mark_weak (decl); |
4b8af8d9 JM |
4552 | } |
4553 | ||
a0203ca7 AO |
4554 | static void |
4555 | weak_finish_1 (tree decl) | |
4b8af8d9 | 4556 | { |
4977bab6 | 4557 | #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL) |
a0203ca7 | 4558 | const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
4977bab6 | 4559 | #endif |
ecb0eece | 4560 | |
a0203ca7 AO |
4561 | if (! TREE_USED (decl)) |
4562 | return; | |
4563 | ||
79c4e63f | 4564 | #ifdef ASM_WEAKEN_DECL |
a0203ca7 | 4565 | ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL); |
4ae08f95 JM |
4566 | #else |
4567 | #ifdef ASM_WEAKEN_LABEL | |
a0203ca7 | 4568 | ASM_WEAKEN_LABEL (asm_out_file, name); |
ecb0eece RH |
4569 | #else |
4570 | #ifdef ASM_OUTPUT_WEAK_ALIAS | |
a0203ca7 AO |
4571 | { |
4572 | static bool warn_once = 0; | |
4573 | if (! warn_once) | |
4574 | { | |
4575 | warning (0, "only weak aliases are supported in this configuration"); | |
4576 | warn_once = 1; | |
4577 | } | |
4578 | return; | |
4579 | } | |
4580 | #endif | |
4ae08f95 | 4581 | #endif |
79c4e63f | 4582 | #endif |
a0203ca7 AO |
4583 | } |
4584 | ||
4585 | /* This TREE_LIST contains weakref targets. */ | |
4586 | ||
4587 | static GTY(()) tree weakref_targets; | |
4588 | ||
4589 | /* Forward declaration. */ | |
4590 | static tree find_decl_and_mark_needed (tree decl, tree target); | |
4591 | ||
4592 | /* Emit any pending weak declarations. */ | |
4593 | ||
4594 | void | |
4595 | weak_finish (void) | |
4596 | { | |
4597 | tree t; | |
4598 | ||
4599 | for (t = weakref_targets; t; t = TREE_CHAIN (t)) | |
4600 | { | |
4601 | tree alias_decl = TREE_PURPOSE (t); | |
4602 | tree target = ultimate_transparent_alias_target (&TREE_VALUE (t)); | |
4603 | ||
4604 | if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl))) | |
4605 | /* Remove alias_decl from the weak list, but leave entries for | |
4606 | the target alone. */ | |
4607 | target = NULL_TREE; | |
4608 | #ifndef ASM_OUTPUT_WEAKREF | |
4609 | else if (! TREE_SYMBOL_REFERENCED (target)) | |
4610 | { | |
ff2d10c1 AO |
4611 | /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not |
4612 | defined, otherwise we and weak_finish_1 would use a | |
4613 | different macros. */ | |
4614 | # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL | |
a0203ca7 AO |
4615 | ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target)); |
4616 | # else | |
4617 | tree decl = find_decl_and_mark_needed (alias_decl, target); | |
4618 | ||
4619 | if (! decl) | |
4620 | { | |
4621 | decl = build_decl (TREE_CODE (alias_decl), target, | |
4622 | TREE_TYPE (alias_decl)); | |
4623 | ||
4624 | DECL_EXTERNAL (decl) = 1; | |
4625 | TREE_PUBLIC (decl) = 1; | |
4626 | DECL_ARTIFICIAL (decl) = 1; | |
4627 | TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl); | |
4628 | TREE_USED (decl) = 1; | |
4629 | } | |
4630 | ||
4631 | weak_finish_1 (decl); | |
4632 | # endif | |
4633 | } | |
4ae08f95 | 4634 | #endif |
a0203ca7 AO |
4635 | |
4636 | { | |
4637 | tree *p; | |
4638 | tree t2; | |
4639 | ||
4640 | /* Remove the alias and the target from the pending weak list | |
4641 | so that we do not emit any .weak directives for the former, | |
4642 | nor multiple .weak directives for the latter. */ | |
4643 | for (p = &weak_decls; (t2 = *p) ; ) | |
4644 | { | |
4645 | if (TREE_VALUE (t2) == alias_decl | |
4646 | || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2))) | |
4647 | *p = TREE_CHAIN (t2); | |
4648 | else | |
4649 | p = &TREE_CHAIN (t2); | |
4650 | } | |
4651 | ||
4652 | /* Remove other weakrefs to the same target, to speed things up. */ | |
4653 | for (p = &TREE_CHAIN (t); (t2 = *p) ; ) | |
4654 | { | |
4655 | if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2))) | |
4656 | *p = TREE_CHAIN (t2); | |
4657 | else | |
4658 | p = &TREE_CHAIN (t2); | |
4659 | } | |
4660 | } | |
4661 | } | |
4662 | ||
4663 | for (t = weak_decls; t; t = TREE_CHAIN (t)) | |
4664 | { | |
4665 | tree decl = TREE_VALUE (t); | |
4666 | ||
4667 | weak_finish_1 (decl); | |
4b8af8d9 | 4668 | } |
4b8af8d9 | 4669 | } |
4ae08f95 | 4670 | |
19c5b1cf JM |
4671 | /* Emit the assembly bits to indicate that DECL is globally visible. */ |
4672 | ||
4673 | static void | |
2e1eedd6 | 4674 | globalize_decl (tree decl) |
19c5b1cf | 4675 | { |
f9d09ae5 | 4676 | const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); |
19c5b1cf JM |
4677 | |
4678 | #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL) | |
4679 | if (DECL_WEAK (decl)) | |
4680 | { | |
ecb0eece RH |
4681 | tree *p, t; |
4682 | ||
19c5b1cf JM |
4683 | #ifdef ASM_WEAKEN_DECL |
4684 | ASM_WEAKEN_DECL (asm_out_file, decl, name, 0); | |
4685 | #else | |
4686 | ASM_WEAKEN_LABEL (asm_out_file, name); | |
4687 | #endif | |
ecb0eece | 4688 | |
19c5b1cf JM |
4689 | /* Remove this function from the pending weak list so that |
4690 | we do not emit multiple .weak directives for it. */ | |
a81eed10 FS |
4691 | for (p = &weak_decls; (t = *p) ; ) |
4692 | { | |
4693 | if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))) | |
ecb0eece | 4694 | *p = TREE_CHAIN (t); |
a81eed10 FS |
4695 | else |
4696 | p = &TREE_CHAIN (t); | |
4697 | } | |
a0203ca7 AO |
4698 | |
4699 | /* Remove weakrefs to the same target from the pending weakref | |
4700 | list, for the same reason. */ | |
4701 | for (p = &weakref_targets; (t = *p) ; ) | |
4702 | { | |
4703 | if (DECL_ASSEMBLER_NAME (decl) | |
4704 | == ultimate_transparent_alias_target (&TREE_VALUE (t))) | |
4705 | *p = TREE_CHAIN (t); | |
4706 | else | |
4707 | p = &TREE_CHAIN (t); | |
4708 | } | |
4709 | ||
19c5b1cf JM |
4710 | return; |
4711 | } | |
4746cf84 MA |
4712 | #elif defined(ASM_MAKE_LABEL_LINKONCE) |
4713 | if (DECL_ONE_ONLY (decl)) | |
4714 | ASM_MAKE_LABEL_LINKONCE (asm_out_file, name); | |
19c5b1cf | 4715 | #endif |
ecb0eece | 4716 | |
5fd9b178 | 4717 | targetm.asm_out.globalize_label (asm_out_file, name); |
19c5b1cf JM |
4718 | } |
4719 | ||
e4d5432a RH |
4720 | /* We have to be able to tell cgraph about the needed-ness of the target |
4721 | of an alias. This requires that the decl have been defined. Aliases | |
aabcd309 | 4722 | that precede their definition have to be queued for later processing. */ |
e4d5432a | 4723 | |
d4e6fecb | 4724 | typedef struct alias_pair GTY(()) |
083b6717 JDA |
4725 | { |
4726 | tree decl; | |
4727 | tree target; | |
d4e6fecb | 4728 | } alias_pair; |
083b6717 JDA |
4729 | |
4730 | /* Define gc'd vector type. */ | |
d4e6fecb NS |
4731 | DEF_VEC_O(alias_pair); |
4732 | DEF_VEC_ALLOC_O(alias_pair,gc); | |
083b6717 | 4733 | |
d4e6fecb | 4734 | static GTY(()) VEC(alias_pair,gc) *alias_pairs; |
083b6717 | 4735 | |
e4d5432a RH |
4736 | /* Given an assembly name, find the decl it is associated with. At the |
4737 | same time, mark it needed for cgraph. */ | |
4738 | ||
4739 | static tree | |
4740 | find_decl_and_mark_needed (tree decl, tree target) | |
4741 | { | |
4742 | struct cgraph_node *fnode = NULL; | |
4743 | struct cgraph_varpool_node *vnode = NULL; | |
4744 | ||
cdcba1ea | 4745 | if (TREE_CODE (decl) == FUNCTION_DECL) |
e4d5432a | 4746 | { |
cdcba1ea AO |
4747 | fnode = cgraph_node_for_asm (target); |
4748 | if (fnode == NULL) | |
4749 | vnode = cgraph_varpool_node_for_asm (target); | |
4750 | } | |
4751 | else | |
4752 | { | |
4753 | vnode = cgraph_varpool_node_for_asm (target); | |
4754 | if (vnode == NULL) | |
4755 | fnode = cgraph_node_for_asm (target); | |
e4d5432a RH |
4756 | } |
4757 | ||
4758 | if (fnode) | |
4759 | { | |
cdcba1ea AO |
4760 | /* We can't mark function nodes as used after cgraph global info |
4761 | is finished. This wouldn't generally be necessary, but C++ | |
4762 | virtual table thunks are introduced late in the game and | |
4763 | might seem like they need marking, although in fact they | |
4764 | don't. */ | |
4765 | if (! cgraph_global_info_ready) | |
4766 | cgraph_mark_needed_node (fnode); | |
e4d5432a RH |
4767 | return fnode->decl; |
4768 | } | |
4769 | else if (vnode) | |
4770 | { | |
4771 | cgraph_varpool_mark_needed_node (vnode); | |
4772 | return vnode->decl; | |
4773 | } | |
083cad55 | 4774 | else |
e4d5432a RH |
4775 | return NULL_TREE; |
4776 | } | |
083b6717 | 4777 | |
749053f5 RS |
4778 | /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF |
4779 | or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose | |
4780 | tree node is DECL to have the value of the tree node TARGET. */ | |
4781 | ||
083b6717 | 4782 | static void |
a0203ca7 | 4783 | do_assemble_alias (tree decl, tree target) |
083b6717 | 4784 | { |
ebccb65d JM |
4785 | if (TREE_ASM_WRITTEN (decl)) |
4786 | return; | |
4787 | ||
e4d5432a RH |
4788 | TREE_ASM_WRITTEN (decl) = 1; |
4789 | TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1; | |
4790 | ||
a0203ca7 AO |
4791 | if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))) |
4792 | { | |
4793 | ultimate_transparent_alias_target (&target); | |
4794 | ||
4795 | if (!TREE_SYMBOL_REFERENCED (target)) | |
4796 | weakref_targets = tree_cons (decl, target, weakref_targets); | |
4797 | ||
4798 | #ifdef ASM_OUTPUT_WEAKREF | |
ff2d10c1 | 4799 | ASM_OUTPUT_WEAKREF (asm_out_file, decl, |
a0203ca7 AO |
4800 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), |
4801 | IDENTIFIER_POINTER (target)); | |
4802 | #else | |
4803 | if (!SUPPORTS_WEAK) | |
4804 | { | |
4805 | error ("%Jweakref is not supported in this configuration", decl); | |
4806 | return; | |
4807 | } | |
4808 | #endif | |
4809 | return; | |
4810 | } | |
4811 | ||
e4d5432a RH |
4812 | #ifdef ASM_OUTPUT_DEF |
4813 | /* Make name accessible from other files, if appropriate. */ | |
4814 | ||
4815 | if (TREE_PUBLIC (decl)) | |
4816 | { | |
4817 | globalize_decl (decl); | |
4818 | maybe_assemble_visibility (decl); | |
4819 | } | |
4820 | ||
4821 | # ifdef ASM_OUTPUT_DEF_FROM_DECLS | |
083b6717 | 4822 | ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target); |
e4d5432a | 4823 | # else |
083b6717 JDA |
4824 | ASM_OUTPUT_DEF (asm_out_file, |
4825 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), | |
4826 | IDENTIFIER_POINTER (target)); | |
e4d5432a RH |
4827 | # endif |
4828 | #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL) | |
4829 | { | |
4830 | const char *name; | |
4831 | tree *p, t; | |
4832 | ||
4833 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
4834 | # ifdef ASM_WEAKEN_DECL | |
4835 | ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target)); | |
4836 | # else | |
4837 | ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target)); | |
4838 | # endif | |
4839 | /* Remove this function from the pending weak list so that | |
4840 | we do not emit multiple .weak directives for it. */ | |
4841 | for (p = &weak_decls; (t = *p) ; ) | |
4842 | if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))) | |
4843 | *p = TREE_CHAIN (t); | |
4844 | else | |
4845 | p = &TREE_CHAIN (t); | |
a0203ca7 AO |
4846 | |
4847 | /* Remove weakrefs to the same target from the pending weakref | |
4848 | list, for the same reason. */ | |
4849 | for (p = &weakref_targets; (t = *p) ; ) | |
4850 | { | |
4851 | if (DECL_ASSEMBLER_NAME (decl) | |
4852 | == ultimate_transparent_alias_target (&TREE_VALUE (t))) | |
4853 | *p = TREE_CHAIN (t); | |
4854 | else | |
4855 | p = &TREE_CHAIN (t); | |
4856 | } | |
e4d5432a | 4857 | } |
083b6717 JDA |
4858 | #endif |
4859 | } | |
083b6717 | 4860 | |
e4d5432a RH |
4861 | /* First pass of completing pending aliases. Make sure that cgraph knows |
4862 | which symbols will be required. */ | |
083b6717 JDA |
4863 | |
4864 | void | |
e4d5432a | 4865 | finish_aliases_1 (void) |
083b6717 | 4866 | { |
083b6717 | 4867 | unsigned i; |
d4e6fecb | 4868 | alias_pair *p; |
083b6717 | 4869 | |
e4d5432a RH |
4870 | for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++) |
4871 | { | |
4872 | tree target_decl; | |
4873 | ||
4874 | target_decl = find_decl_and_mark_needed (p->decl, p->target); | |
4875 | if (target_decl == NULL) | |
a0203ca7 AO |
4876 | { |
4877 | if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl))) | |
4878 | error ("%q+D aliased to undefined symbol %qs", | |
4879 | p->decl, IDENTIFIER_POINTER (p->target)); | |
4880 | } | |
4881 | else if (DECL_EXTERNAL (target_decl) | |
4882 | && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl))) | |
ea40ba9c JM |
4883 | error ("%q+D aliased to external symbol %qs", |
4884 | p->decl, IDENTIFIER_POINTER (p->target)); | |
e4d5432a RH |
4885 | } |
4886 | } | |
083b6717 | 4887 | |
e4d5432a RH |
4888 | /* Second pass of completing pending aliases. Emit the actual assembly. |
4889 | This happens at the end of compilation and thus it is assured that the | |
4890 | target symbol has been emitted. */ | |
4891 | ||
4892 | void | |
4893 | finish_aliases_2 (void) | |
4894 | { | |
4895 | unsigned i; | |
d4e6fecb | 4896 | alias_pair *p; |
e4d5432a RH |
4897 | |
4898 | for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++) | |
4899 | do_assemble_alias (p->decl, p->target); | |
4900 | ||
d4e6fecb | 4901 | VEC_truncate (alias_pair, alias_pairs, 0); |
083b6717 JDA |
4902 | } |
4903 | ||
4ae08f95 JM |
4904 | /* Emit an assembler directive to make the symbol for DECL an alias to |
4905 | the symbol for TARGET. */ | |
4b8af8d9 JM |
4906 | |
4907 | void | |
bedb9fc0 | 4908 | assemble_alias (tree decl, tree target) |
4b8af8d9 | 4909 | { |
e4d5432a | 4910 | tree target_decl; |
a0203ca7 | 4911 | bool is_weakref = false; |
4b8af8d9 | 4912 | |
a0203ca7 AO |
4913 | if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))) |
4914 | { | |
4915 | tree alias = DECL_ASSEMBLER_NAME (decl); | |
4916 | ||
4917 | is_weakref = true; | |
4918 | ||
4919 | ultimate_transparent_alias_target (&target); | |
4920 | ||
4921 | if (alias == target) | |
6d3e3e6a | 4922 | error ("weakref %q+D ultimately targets itself", decl); |
a0203ca7 AO |
4923 | else |
4924 | { | |
4925 | #ifndef ASM_OUTPUT_WEAKREF | |
4926 | IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1; | |
4927 | TREE_CHAIN (alias) = target; | |
4928 | #endif | |
4929 | } | |
a9b0b825 GK |
4930 | if (TREE_PUBLIC (decl)) |
4931 | error ("weakref %q+D must have static linkage", decl); | |
a0203ca7 AO |
4932 | } |
4933 | else | |
4934 | { | |
e4d5432a RH |
4935 | #if !defined (ASM_OUTPUT_DEF) |
4936 | # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL) | |
a0203ca7 | 4937 | error ("%Jalias definitions not supported in this configuration", decl); |
e4d5432a | 4938 | return; |
a0203ca7 AO |
4939 | # else |
4940 | if (!DECL_WEAK (decl)) | |
4941 | { | |
4942 | error ("%Jonly weak aliases are supported in this configuration", decl); | |
4943 | return; | |
4944 | } | |
e4d5432a RH |
4945 | # endif |
4946 | #endif | |
a0203ca7 | 4947 | } |
4b8af8d9 | 4948 | |
e4d5432a RH |
4949 | /* We must force creation of DECL_RTL for debug info generation, even though |
4950 | we don't use it here. */ | |
4951 | make_decl_rtl (decl); | |
4952 | TREE_USED (decl) = 1; | |
083b6717 | 4953 | |
e4d5432a RH |
4954 | /* A quirk of the initial implementation of aliases required that the user |
4955 | add "extern" to all of them. Which is silly, but now historical. Do | |
4956 | note that the symbol is in fact locally defined. */ | |
a0203ca7 AO |
4957 | if (! is_weakref) |
4958 | DECL_EXTERNAL (decl) = 0; | |
083b6717 | 4959 | |
e4d5432a RH |
4960 | /* Allow aliases to aliases. */ |
4961 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
12527dce | 4962 | cgraph_node (decl)->alias = true; |
06e4eab5 | 4963 | else |
1a612e0a | 4964 | cgraph_varpool_node (decl)->alias = true; |
06e4eab5 | 4965 | |
e4d5432a RH |
4966 | /* If the target has already been emitted, we don't have to queue the |
4967 | alias. This saves a tad o memory. */ | |
4968 | target_decl = find_decl_and_mark_needed (decl, target); | |
4969 | if (target_decl && TREE_ASM_WRITTEN (target_decl)) | |
4970 | do_assemble_alias (decl, target); | |
4971 | else | |
bedb9fc0 | 4972 | { |
d4e6fecb | 4973 | alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL); |
e4d5432a RH |
4974 | p->decl = decl; |
4975 | p->target = target; | |
bedb9fc0 | 4976 | } |
4b8af8d9 | 4977 | } |
f796d997 | 4978 | |
47bd70b5 | 4979 | /* Emit an assembler directive to set symbol for DECL visibility to |
25fdb4dc | 4980 | the visibility type VIS, which must not be VISIBILITY_DEFAULT. */ |
47bd70b5 JJ |
4981 | |
4982 | void | |
2e1eedd6 | 4983 | default_assemble_visibility (tree decl, int vis) |
47bd70b5 | 4984 | { |
25fdb4dc RH |
4985 | static const char * const visibility_types[] = { |
4986 | NULL, "internal", "hidden", "protected" | |
4987 | }; | |
4988 | ||
4989 | const char *name, *type; | |
47bd70b5 | 4990 | |
b0250067 | 4991 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
25fdb4dc | 4992 | type = visibility_types[vis]; |
47bd70b5 JJ |
4993 | |
4994 | #ifdef HAVE_GAS_HIDDEN | |
267594f3 R |
4995 | fprintf (asm_out_file, "\t.%s\t", type); |
4996 | assemble_name (asm_out_file, name); | |
4997 | fprintf (asm_out_file, "\n"); | |
47bd70b5 | 4998 | #else |
5c498b10 DD |
4999 | warning (OPT_Wattributes, "visibility attribute not supported " |
5000 | "in this configuration; ignored"); | |
47bd70b5 JJ |
5001 | #endif |
5002 | } | |
5003 | ||
b14707c3 RH |
5004 | /* A helper function to call assemble_visibility when needed for a decl. */ |
5005 | ||
5006 | static void | |
2e1eedd6 | 5007 | maybe_assemble_visibility (tree decl) |
b14707c3 | 5008 | { |
968b41a1 | 5009 | enum symbol_visibility vis = DECL_VISIBILITY (decl); |
25fdb4dc RH |
5010 | |
5011 | if (vis != VISIBILITY_DEFAULT) | |
245f1bfa | 5012 | targetm.asm_out.visibility (decl, vis); |
b14707c3 RH |
5013 | } |
5014 | ||
f796d997 JM |
5015 | /* Returns 1 if the target configuration supports defining public symbols |
5016 | so that one of them will be chosen at link time instead of generating a | |
5017 | multiply-defined symbol error, whether through the use of weak symbols or | |
5018 | a target-specific mechanism for having duplicates discarded. */ | |
5019 | ||
5020 | int | |
2e1eedd6 | 5021 | supports_one_only (void) |
f796d997 JM |
5022 | { |
5023 | if (SUPPORTS_ONE_ONLY) | |
5024 | return 1; | |
5025 | return SUPPORTS_WEAK; | |
5026 | } | |
5027 | ||
5028 | /* Set up DECL as a public symbol that can be defined in multiple | |
5029 | translation units without generating a linker error. */ | |
5030 | ||
5031 | void | |
2e1eedd6 | 5032 | make_decl_one_only (tree decl) |
f796d997 | 5033 | { |
fbc848cc NS |
5034 | gcc_assert (TREE_CODE (decl) == VAR_DECL |
5035 | || TREE_CODE (decl) == FUNCTION_DECL); | |
f796d997 JM |
5036 | |
5037 | TREE_PUBLIC (decl) = 1; | |
5038 | ||
4746cf84 | 5039 | if (SUPPORTS_ONE_ONLY) |
f796d997 JM |
5040 | { |
5041 | #ifdef MAKE_DECL_ONE_ONLY | |
5042 | MAKE_DECL_ONE_ONLY (decl); | |
5043 | #endif | |
5044 | DECL_ONE_ONLY (decl) = 1; | |
5045 | } | |
4746cf84 MA |
5046 | else if (TREE_CODE (decl) == VAR_DECL |
5047 | && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)) | |
5048 | DECL_COMMON (decl) = 1; | |
f796d997 | 5049 | else |
fbc848cc NS |
5050 | { |
5051 | gcc_assert (SUPPORTS_WEAK); | |
5052 | DECL_WEAK (decl) = 1; | |
5053 | } | |
f796d997 | 5054 | } |
76095e2f RH |
5055 | |
5056 | void | |
2e1eedd6 | 5057 | init_varasm_once (void) |
76095e2f | 5058 | { |
d6b5193b RS |
5059 | section_htab = htab_create_ggc (31, section_entry_hash, |
5060 | section_entry_eq, NULL); | |
aacd3885 RS |
5061 | object_block_htab = htab_create_ggc (31, object_block_entry_hash, |
5062 | object_block_entry_eq, NULL); | |
10b6a274 ZW |
5063 | const_desc_htab = htab_create_ggc (1009, const_desc_hash, |
5064 | const_desc_eq, NULL); | |
715bdd29 | 5065 | |
a79e3a45 | 5066 | const_alias_set = new_alias_set (); |
d6b5193b RS |
5067 | |
5068 | #ifdef TEXT_SECTION_ASM_OP | |
5069 | text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op, | |
5070 | TEXT_SECTION_ASM_OP); | |
5071 | #endif | |
5072 | ||
5073 | #ifdef DATA_SECTION_ASM_OP | |
5074 | data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op, | |
5075 | DATA_SECTION_ASM_OP); | |
5076 | #endif | |
5077 | ||
5078 | #ifdef SDATA_SECTION_ASM_OP | |
5079 | sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op, | |
5080 | SDATA_SECTION_ASM_OP); | |
5081 | #endif | |
5082 | ||
5083 | #ifdef READONLY_DATA_SECTION_ASM_OP | |
5084 | readonly_data_section = get_unnamed_section (0, output_section_asm_op, | |
5085 | READONLY_DATA_SECTION_ASM_OP); | |
5086 | #endif | |
5087 | ||
5088 | #ifdef CTORS_SECTION_ASM_OP | |
5089 | ctors_section = get_unnamed_section (0, output_section_asm_op, | |
5090 | CTORS_SECTION_ASM_OP); | |
5091 | #endif | |
5092 | ||
5093 | #ifdef DTORS_SECTION_ASM_OP | |
5094 | dtors_section = get_unnamed_section (0, output_section_asm_op, | |
5095 | DTORS_SECTION_ASM_OP); | |
5096 | #endif | |
5097 | ||
5098 | #ifdef BSS_SECTION_ASM_OP | |
5099 | bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS, | |
5100 | output_section_asm_op, | |
5101 | BSS_SECTION_ASM_OP); | |
5102 | #endif | |
5103 | ||
5104 | #ifdef SBSS_SECTION_ASM_OP | |
5105 | sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS, | |
5106 | output_section_asm_op, | |
5107 | SBSS_SECTION_ASM_OP); | |
5108 | #endif | |
5109 | ||
434aeebb RS |
5110 | tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS |
5111 | | SECTION_COMMON, emit_tls_common); | |
5112 | lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS | |
5113 | | SECTION_COMMON, emit_local); | |
5114 | comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS | |
5115 | | SECTION_COMMON, emit_common); | |
5116 | ||
5117 | #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS | |
5118 | bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS, | |
5119 | emit_bss); | |
5120 | #endif | |
5121 | ||
d6b5193b RS |
5122 | targetm.asm_out.init_sections (); |
5123 | ||
5124 | if (readonly_data_section == NULL) | |
5125 | readonly_data_section = text_section; | |
76095e2f | 5126 | } |
7c262518 | 5127 | |
c2f7fa15 SB |
5128 | enum tls_model |
5129 | decl_default_tls_model (tree decl) | |
dce81a1a JJ |
5130 | { |
5131 | enum tls_model kind; | |
dce81a1a JJ |
5132 | bool is_local; |
5133 | ||
5fd9b178 | 5134 | is_local = targetm.binds_local_p (decl); |
0bfb33e5 | 5135 | if (!flag_shlib) |
dce81a1a JJ |
5136 | { |
5137 | if (is_local) | |
5138 | kind = TLS_MODEL_LOCAL_EXEC; | |
5139 | else | |
5140 | kind = TLS_MODEL_INITIAL_EXEC; | |
5141 | } | |
c2f7fa15 | 5142 | |
dce81a1a JJ |
5143 | /* Local dynamic is inefficient when we're not combining the |
5144 | parts of the address. */ | |
5145 | else if (optimize && is_local) | |
5146 | kind = TLS_MODEL_LOCAL_DYNAMIC; | |
5147 | else | |
5148 | kind = TLS_MODEL_GLOBAL_DYNAMIC; | |
5149 | if (kind < flag_tls_default) | |
5150 | kind = flag_tls_default; | |
5151 | ||
5152 | return kind; | |
5153 | } | |
5154 | ||
7c262518 RH |
5155 | /* Select a set of attributes for section NAME based on the properties |
5156 | of DECL and whether or not RELOC indicates that DECL's initializer | |
5157 | might contain runtime relocations. | |
5158 | ||
5159 | We make the section read-only and executable for a function decl, | |
715bdd29 | 5160 | read-only for a const data decl, and writable for a non-const data decl. */ |
7c262518 RH |
5161 | |
5162 | unsigned int | |
2e1eedd6 | 5163 | default_section_type_flags (tree decl, const char *name, int reloc) |
2cc9fb4c DE |
5164 | { |
5165 | return default_section_type_flags_1 (decl, name, reloc, flag_pic); | |
5166 | } | |
5167 | ||
5168 | unsigned int | |
2e1eedd6 AJ |
5169 | default_section_type_flags_1 (tree decl, const char *name, int reloc, |
5170 | int shlib) | |
7c262518 | 5171 | { |
7c262518 | 5172 | unsigned int flags; |
7c262518 RH |
5173 | |
5174 | if (decl && TREE_CODE (decl) == FUNCTION_DECL) | |
5175 | flags = SECTION_CODE; | |
2cc9fb4c | 5176 | else if (decl && decl_readonly_section_1 (decl, reloc, shlib)) |
7c262518 | 5177 | flags = 0; |
c7466dee CT |
5178 | else if (current_function_decl |
5179 | && cfun | |
5180 | && cfun->unlikely_text_section_name | |
5181 | && strcmp (name, cfun->unlikely_text_section_name) == 0) | |
750054a2 | 5182 | flags = SECTION_CODE; |
083cad55 | 5183 | else if (!decl |
c7466dee CT |
5184 | && (!current_function_decl || !cfun) |
5185 | && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0) | |
083cad55 | 5186 | flags = SECTION_CODE; |
7c262518 RH |
5187 | else |
5188 | flags = SECTION_WRITE; | |
5189 | ||
5190 | if (decl && DECL_ONE_ONLY (decl)) | |
5191 | flags |= SECTION_LINKONCE; | |
5192 | ||
c2f7fa15 | 5193 | if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)) |
c711ba8e RH |
5194 | flags |= SECTION_TLS | SECTION_WRITE; |
5195 | ||
7c262518 RH |
5196 | if (strcmp (name, ".bss") == 0 |
5197 | || strncmp (name, ".bss.", 5) == 0 | |
abb8b19a AM |
5198 | || strncmp (name, ".gnu.linkonce.b.", 16) == 0 |
5199 | || strcmp (name, ".sbss") == 0 | |
826eb7ed JB |
5200 | || strncmp (name, ".sbss.", 6) == 0 |
5201 | || strncmp (name, ".gnu.linkonce.sb.", 17) == 0) | |
abb8b19a | 5202 | flags |= SECTION_BSS; |
826eb7ed | 5203 | |
3d78f2e9 | 5204 | if (strcmp (name, ".tdata") == 0 |
826eb7ed JB |
5205 | || strncmp (name, ".tdata.", 7) == 0 |
5206 | || strncmp (name, ".gnu.linkonce.td.", 17) == 0) | |
3d78f2e9 RH |
5207 | flags |= SECTION_TLS; |
5208 | ||
826eb7ed JB |
5209 | if (strcmp (name, ".tbss") == 0 |
5210 | || strncmp (name, ".tbss.", 6) == 0 | |
5211 | || strncmp (name, ".gnu.linkonce.tb.", 17) == 0) | |
5212 | flags |= SECTION_TLS | SECTION_BSS; | |
5213 | ||
6a0a6ac4 AM |
5214 | /* These three sections have special ELF types. They are neither |
5215 | SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't | |
5216 | want to print a section type (@progbits or @nobits). If someone | |
5217 | is silly enough to emit code or TLS variables to one of these | |
5218 | sections, then don't handle them specially. */ | |
5219 | if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS)) | |
5220 | && (strcmp (name, ".init_array") == 0 | |
5221 | || strcmp (name, ".fini_array") == 0 | |
5222 | || strcmp (name, ".preinit_array") == 0)) | |
5223 | flags |= SECTION_NOTYPE; | |
5224 | ||
7c262518 RH |
5225 | return flags; |
5226 | } | |
5227 | ||
434aeebb RS |
5228 | /* Return true if the target supports some form of global BSS, |
5229 | either through bss_noswitch_section, or by selecting a BSS | |
5230 | section in TARGET_ASM_SELECT_SECTION. */ | |
5231 | ||
5232 | bool | |
5233 | have_global_bss_p (void) | |
5234 | { | |
5235 | return bss_noswitch_section || targetm.have_switchable_bss_sections; | |
5236 | } | |
5237 | ||
7c262518 RH |
5238 | /* Output assembly to switch to section NAME with attribute FLAGS. |
5239 | Four variants for common object file formats. */ | |
5240 | ||
5241 | void | |
2e1eedd6 | 5242 | default_no_named_section (const char *name ATTRIBUTE_UNUSED, |
c18a5b6c MM |
5243 | unsigned int flags ATTRIBUTE_UNUSED, |
5244 | tree decl ATTRIBUTE_UNUSED) | |
7c262518 RH |
5245 | { |
5246 | /* Some object formats don't support named sections at all. The | |
5247 | front-end should already have flagged this as an error. */ | |
fbc848cc | 5248 | gcc_unreachable (); |
7c262518 RH |
5249 | } |
5250 | ||
5251 | void | |
c18a5b6c MM |
5252 | default_elf_asm_named_section (const char *name, unsigned int flags, |
5253 | tree decl ATTRIBUTE_UNUSED) | |
7c262518 | 5254 | { |
201556f0 | 5255 | char flagchars[10], *f = flagchars; |
7c262518 | 5256 | |
c18a5b6c MM |
5257 | /* If we have already declared this section, we can use an |
5258 | abbreviated form to switch back to it -- unless this section is | |
5259 | part of a COMDAT groups, in which case GAS requires the full | |
5260 | declaration every time. */ | |
11176d2a | 5261 | if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) |
d6b5193b | 5262 | && (flags & SECTION_DECLARED)) |
a8c01a59 RL |
5263 | { |
5264 | fprintf (asm_out_file, "\t.section\t%s\n", name); | |
5265 | return; | |
5266 | } | |
5267 | ||
7c262518 RH |
5268 | if (!(flags & SECTION_DEBUG)) |
5269 | *f++ = 'a'; | |
5270 | if (flags & SECTION_WRITE) | |
5271 | *f++ = 'w'; | |
5272 | if (flags & SECTION_CODE) | |
5273 | *f++ = 'x'; | |
5274 | if (flags & SECTION_SMALL) | |
5275 | *f++ = 's'; | |
201556f0 JJ |
5276 | if (flags & SECTION_MERGE) |
5277 | *f++ = 'M'; | |
5278 | if (flags & SECTION_STRINGS) | |
5279 | *f++ = 'S'; | |
3d78f2e9 RH |
5280 | if (flags & SECTION_TLS) |
5281 | *f++ = 'T'; | |
11176d2a | 5282 | if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) |
c18a5b6c | 5283 | *f++ = 'G'; |
7c262518 RH |
5284 | *f = '\0'; |
5285 | ||
6a0a6ac4 | 5286 | fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars); |
7c262518 | 5287 | |
6a0a6ac4 AM |
5288 | if (!(flags & SECTION_NOTYPE)) |
5289 | { | |
5290 | const char *type; | |
c18a5b6c | 5291 | const char *format; |
6a0a6ac4 AM |
5292 | |
5293 | if (flags & SECTION_BSS) | |
5294 | type = "nobits"; | |
5295 | else | |
5296 | type = "progbits"; | |
5297 | ||
c18a5b6c MM |
5298 | format = ",@%s"; |
5299 | #ifdef ASM_COMMENT_START | |
5300 | /* On platforms that use "@" as the assembly comment character, | |
5301 | use "%" instead. */ | |
5302 | if (strcmp (ASM_COMMENT_START, "@") == 0) | |
5303 | format = ",%%%s"; | |
5304 | #endif | |
5305 | fprintf (asm_out_file, format, type); | |
6a0a6ac4 AM |
5306 | |
5307 | if (flags & SECTION_ENTSIZE) | |
5308 | fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE); | |
11176d2a | 5309 | if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) |
083cad55 | 5310 | fprintf (asm_out_file, ",%s,comdat", |
c18a5b6c | 5311 | lang_hooks.decls.comdat_group (decl)); |
6a0a6ac4 AM |
5312 | } |
5313 | ||
5314 | putc ('\n', asm_out_file); | |
7c262518 RH |
5315 | } |
5316 | ||
5317 | void | |
083cad55 | 5318 | default_coff_asm_named_section (const char *name, unsigned int flags, |
c18a5b6c | 5319 | tree decl ATTRIBUTE_UNUSED) |
7c262518 RH |
5320 | { |
5321 | char flagchars[8], *f = flagchars; | |
5322 | ||
5323 | if (flags & SECTION_WRITE) | |
5324 | *f++ = 'w'; | |
5325 | if (flags & SECTION_CODE) | |
5326 | *f++ = 'x'; | |
5327 | *f = '\0'; | |
5328 | ||
5329 | fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars); | |
5330 | } | |
5331 | ||
5332 | void | |
c18a5b6c MM |
5333 | default_pe_asm_named_section (const char *name, unsigned int flags, |
5334 | tree decl) | |
7c262518 | 5335 | { |
c18a5b6c | 5336 | default_coff_asm_named_section (name, flags, decl); |
7c262518 RH |
5337 | |
5338 | if (flags & SECTION_LINKONCE) | |
5339 | { | |
5340 | /* Functions may have been compiled at various levels of | |
5341 | optimization so we can't use `same_size' here. | |
5342 | Instead, have the linker pick one. */ | |
5343 | fprintf (asm_out_file, "\t.linkonce %s\n", | |
5344 | (flags & SECTION_CODE ? "discard" : "same_size")); | |
5345 | } | |
5346 | } | |
4a8d0c9c | 5347 | \f |
ae46c4e0 RH |
5348 | /* The lame default section selector. */ |
5349 | ||
d6b5193b | 5350 | section * |
2e1eedd6 AJ |
5351 | default_select_section (tree decl, int reloc, |
5352 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
ae46c4e0 | 5353 | { |
ae46c4e0 RH |
5354 | if (DECL_P (decl)) |
5355 | { | |
4e4d733e | 5356 | if (decl_readonly_section (decl, reloc)) |
d6b5193b | 5357 | return readonly_data_section; |
ae46c4e0 RH |
5358 | } |
5359 | else if (TREE_CODE (decl) == CONSTRUCTOR) | |
5360 | { | |
5361 | if (! ((flag_pic && reloc) | |
5362 | || !TREE_READONLY (decl) | |
5363 | || TREE_SIDE_EFFECTS (decl) | |
5364 | || !TREE_CONSTANT (decl))) | |
d6b5193b | 5365 | return readonly_data_section; |
ae46c4e0 RH |
5366 | } |
5367 | else if (TREE_CODE (decl) == STRING_CST) | |
d6b5193b | 5368 | return readonly_data_section; |
ae46c4e0 | 5369 | else if (! (flag_pic && reloc)) |
d6b5193b | 5370 | return readonly_data_section; |
ae46c4e0 | 5371 | |
d6b5193b | 5372 | return data_section; |
ae46c4e0 RH |
5373 | } |
5374 | ||
ae46c4e0 | 5375 | enum section_category |
2e1eedd6 | 5376 | categorize_decl_for_section (tree decl, int reloc, int shlib) |
ae46c4e0 RH |
5377 | { |
5378 | enum section_category ret; | |
5379 | ||
5380 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
5381 | return SECCAT_TEXT; | |
5382 | else if (TREE_CODE (decl) == STRING_CST) | |
6de9cd9a DN |
5383 | { |
5384 | if (flag_mudflap) /* or !flag_merge_constants */ | |
5385 | return SECCAT_RODATA; | |
5386 | else | |
5387 | return SECCAT_RODATA_MERGE_STR; | |
5388 | } | |
ae46c4e0 RH |
5389 | else if (TREE_CODE (decl) == VAR_DECL) |
5390 | { | |
434aeebb | 5391 | if (bss_initializer_p (decl)) |
ae46c4e0 RH |
5392 | ret = SECCAT_BSS; |
5393 | else if (! TREE_READONLY (decl) | |
5394 | || TREE_SIDE_EFFECTS (decl) | |
5395 | || ! TREE_CONSTANT (DECL_INITIAL (decl))) | |
5396 | { | |
2cc9fb4c | 5397 | if (shlib && (reloc & 2)) |
ae46c4e0 | 5398 | ret = SECCAT_DATA_REL; |
2cc9fb4c | 5399 | else if (shlib && reloc) |
ae46c4e0 RH |
5400 | ret = SECCAT_DATA_REL_LOCAL; |
5401 | else | |
5402 | ret = SECCAT_DATA; | |
5403 | } | |
2cc9fb4c | 5404 | else if (shlib && (reloc & 2)) |
ae46c4e0 | 5405 | ret = SECCAT_DATA_REL_RO; |
2cc9fb4c | 5406 | else if (shlib && reloc) |
ae46c4e0 | 5407 | ret = SECCAT_DATA_REL_RO_LOCAL; |
7eca317a | 5408 | else if (reloc || flag_merge_constants < 2) |
ae46c4e0 RH |
5409 | /* C and C++ don't allow different variables to share the same |
5410 | location. -fmerge-all-constants allows even that (at the | |
5411 | expense of not conforming). */ | |
5412 | ret = SECCAT_RODATA; | |
5413 | else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST) | |
5414 | ret = SECCAT_RODATA_MERGE_STR_INIT; | |
5415 | else | |
5416 | ret = SECCAT_RODATA_MERGE_CONST; | |
5417 | } | |
5418 | else if (TREE_CODE (decl) == CONSTRUCTOR) | |
5419 | { | |
2cc9fb4c | 5420 | if ((shlib && reloc) |
ae46c4e0 RH |
5421 | || TREE_SIDE_EFFECTS (decl) |
5422 | || ! TREE_CONSTANT (decl)) | |
5423 | ret = SECCAT_DATA; | |
5424 | else | |
5425 | ret = SECCAT_RODATA; | |
5426 | } | |
5427 | else | |
5428 | ret = SECCAT_RODATA; | |
5429 | ||
3d78f2e9 | 5430 | /* There are no read-only thread-local sections. */ |
c2f7fa15 | 5431 | if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)) |
3d78f2e9 | 5432 | { |
08a8c6b6 JB |
5433 | /* Note that this would be *just* SECCAT_BSS, except that there's |
5434 | no concept of a read-only thread-local-data section. */ | |
5435 | if (ret == SECCAT_BSS | |
5436 | || (flag_zero_initialized_in_bss | |
5437 | && initializer_zerop (DECL_INITIAL (decl)))) | |
3d78f2e9 RH |
5438 | ret = SECCAT_TBSS; |
5439 | else | |
5440 | ret = SECCAT_TDATA; | |
5441 | } | |
5442 | ||
ae46c4e0 | 5443 | /* If the target uses small data sections, select it. */ |
5fd9b178 | 5444 | else if (targetm.in_small_data_p (decl)) |
ae46c4e0 RH |
5445 | { |
5446 | if (ret == SECCAT_BSS) | |
5447 | ret = SECCAT_SBSS; | |
275b6d80 DE |
5448 | else if (targetm.have_srodata_section && ret == SECCAT_RODATA) |
5449 | ret = SECCAT_SRODATA; | |
ae46c4e0 RH |
5450 | else |
5451 | ret = SECCAT_SDATA; | |
5452 | } | |
5453 | ||
5454 | return ret; | |
5455 | } | |
5456 | ||
4e4d733e | 5457 | bool |
2e1eedd6 | 5458 | decl_readonly_section (tree decl, int reloc) |
4e4d733e | 5459 | { |
2cc9fb4c DE |
5460 | return decl_readonly_section_1 (decl, reloc, flag_pic); |
5461 | } | |
5462 | ||
5463 | bool | |
2e1eedd6 | 5464 | decl_readonly_section_1 (tree decl, int reloc, int shlib) |
2cc9fb4c DE |
5465 | { |
5466 | switch (categorize_decl_for_section (decl, reloc, shlib)) | |
4e4d733e L |
5467 | { |
5468 | case SECCAT_RODATA: | |
5469 | case SECCAT_RODATA_MERGE_STR: | |
5470 | case SECCAT_RODATA_MERGE_STR_INIT: | |
5471 | case SECCAT_RODATA_MERGE_CONST: | |
275b6d80 | 5472 | case SECCAT_SRODATA: |
4e4d733e L |
5473 | return true; |
5474 | break; | |
5475 | default: | |
5476 | return false; | |
5477 | break; | |
5478 | } | |
5479 | } | |
5480 | ||
ae46c4e0 RH |
5481 | /* Select a section based on the above categorization. */ |
5482 | ||
d6b5193b | 5483 | section * |
2e1eedd6 AJ |
5484 | default_elf_select_section (tree decl, int reloc, |
5485 | unsigned HOST_WIDE_INT align) | |
ae46c4e0 | 5486 | { |
d6b5193b | 5487 | return default_elf_select_section_1 (decl, reloc, align, flag_pic); |
2cc9fb4c DE |
5488 | } |
5489 | ||
d6b5193b | 5490 | section * |
2e1eedd6 AJ |
5491 | default_elf_select_section_1 (tree decl, int reloc, |
5492 | unsigned HOST_WIDE_INT align, int shlib) | |
2cc9fb4c | 5493 | { |
e13971e0 | 5494 | const char *sname; |
2cc9fb4c | 5495 | switch (categorize_decl_for_section (decl, reloc, shlib)) |
ae46c4e0 RH |
5496 | { |
5497 | case SECCAT_TEXT: | |
5498 | /* We're not supposed to be called on FUNCTION_DECLs. */ | |
fbc848cc | 5499 | gcc_unreachable (); |
ae46c4e0 | 5500 | case SECCAT_RODATA: |
d6b5193b | 5501 | return readonly_data_section; |
ae46c4e0 | 5502 | case SECCAT_RODATA_MERGE_STR: |
d6b5193b | 5503 | return mergeable_string_section (decl, align, 0); |
ae46c4e0 | 5504 | case SECCAT_RODATA_MERGE_STR_INIT: |
d6b5193b | 5505 | return mergeable_string_section (DECL_INITIAL (decl), align, 0); |
ae46c4e0 | 5506 | case SECCAT_RODATA_MERGE_CONST: |
d6b5193b | 5507 | return mergeable_constant_section (DECL_MODE (decl), align, 0); |
275b6d80 | 5508 | case SECCAT_SRODATA: |
e13971e0 | 5509 | sname = ".sdata2"; |
275b6d80 | 5510 | break; |
ae46c4e0 | 5511 | case SECCAT_DATA: |
d6b5193b | 5512 | return data_section; |
ae46c4e0 | 5513 | case SECCAT_DATA_REL: |
e13971e0 | 5514 | sname = ".data.rel"; |
ae46c4e0 RH |
5515 | break; |
5516 | case SECCAT_DATA_REL_LOCAL: | |
e13971e0 | 5517 | sname = ".data.rel.local"; |
ae46c4e0 RH |
5518 | break; |
5519 | case SECCAT_DATA_REL_RO: | |
e13971e0 | 5520 | sname = ".data.rel.ro"; |
ae46c4e0 RH |
5521 | break; |
5522 | case SECCAT_DATA_REL_RO_LOCAL: | |
e13971e0 | 5523 | sname = ".data.rel.ro.local"; |
ae46c4e0 RH |
5524 | break; |
5525 | case SECCAT_SDATA: | |
e13971e0 | 5526 | sname = ".sdata"; |
ae46c4e0 RH |
5527 | break; |
5528 | case SECCAT_TDATA: | |
e13971e0 | 5529 | sname = ".tdata"; |
ae46c4e0 RH |
5530 | break; |
5531 | case SECCAT_BSS: | |
d6b5193b RS |
5532 | if (bss_section) |
5533 | return bss_section; | |
e13971e0 | 5534 | sname = ".bss"; |
ae46c4e0 RH |
5535 | break; |
5536 | case SECCAT_SBSS: | |
e13971e0 | 5537 | sname = ".sbss"; |
ae46c4e0 RH |
5538 | break; |
5539 | case SECCAT_TBSS: | |
e13971e0 | 5540 | sname = ".tbss"; |
ae46c4e0 RH |
5541 | break; |
5542 | default: | |
fbc848cc | 5543 | gcc_unreachable (); |
ae46c4e0 | 5544 | } |
e13971e0 AM |
5545 | |
5546 | if (!DECL_P (decl)) | |
5547 | decl = NULL_TREE; | |
d6b5193b | 5548 | return get_named_section (decl, sname, reloc); |
ae46c4e0 RH |
5549 | } |
5550 | ||
41077ce4 | 5551 | /* Construct a unique section name based on the decl name and the |
ae46c4e0 RH |
5552 | categorization performed above. */ |
5553 | ||
5554 | void | |
2e1eedd6 | 5555 | default_unique_section (tree decl, int reloc) |
2cc9fb4c DE |
5556 | { |
5557 | default_unique_section_1 (decl, reloc, flag_pic); | |
5558 | } | |
5559 | ||
5560 | void | |
2e1eedd6 | 5561 | default_unique_section_1 (tree decl, int reloc, int shlib) |
ae46c4e0 | 5562 | { |
11176d2a JB |
5563 | /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */ |
5564 | bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP; | |
ae46c4e0 RH |
5565 | const char *prefix, *name; |
5566 | size_t nlen, plen; | |
5567 | char *string; | |
5568 | ||
2cc9fb4c | 5569 | switch (categorize_decl_for_section (decl, reloc, shlib)) |
ae46c4e0 RH |
5570 | { |
5571 | case SECCAT_TEXT: | |
5572 | prefix = one_only ? ".gnu.linkonce.t." : ".text."; | |
5573 | break; | |
5574 | case SECCAT_RODATA: | |
5575 | case SECCAT_RODATA_MERGE_STR: | |
5576 | case SECCAT_RODATA_MERGE_STR_INIT: | |
5577 | case SECCAT_RODATA_MERGE_CONST: | |
5578 | prefix = one_only ? ".gnu.linkonce.r." : ".rodata."; | |
5579 | break; | |
275b6d80 DE |
5580 | case SECCAT_SRODATA: |
5581 | prefix = one_only ? ".gnu.linkonce.s2." : ".sdata2."; | |
5582 | break; | |
ae46c4e0 | 5583 | case SECCAT_DATA: |
0a942fea JJ |
5584 | prefix = one_only ? ".gnu.linkonce.d." : ".data."; |
5585 | break; | |
ae46c4e0 | 5586 | case SECCAT_DATA_REL: |
0a942fea JJ |
5587 | prefix = one_only ? ".gnu.linkonce.d.rel." : ".data.rel."; |
5588 | break; | |
ae46c4e0 | 5589 | case SECCAT_DATA_REL_LOCAL: |
0a942fea JJ |
5590 | prefix = one_only ? ".gnu.linkonce.d.rel.local." : ".data.rel.local."; |
5591 | break; | |
ae46c4e0 | 5592 | case SECCAT_DATA_REL_RO: |
0a942fea JJ |
5593 | prefix = one_only ? ".gnu.linkonce.d.rel.ro." : ".data.rel.ro."; |
5594 | break; | |
ae46c4e0 | 5595 | case SECCAT_DATA_REL_RO_LOCAL: |
0a942fea JJ |
5596 | prefix = one_only ? ".gnu.linkonce.d.rel.ro.local." |
5597 | : ".data.rel.ro.local."; | |
ae46c4e0 RH |
5598 | break; |
5599 | case SECCAT_SDATA: | |
5600 | prefix = one_only ? ".gnu.linkonce.s." : ".sdata."; | |
5601 | break; | |
5602 | case SECCAT_BSS: | |
5603 | prefix = one_only ? ".gnu.linkonce.b." : ".bss."; | |
5604 | break; | |
5605 | case SECCAT_SBSS: | |
5606 | prefix = one_only ? ".gnu.linkonce.sb." : ".sbss."; | |
5607 | break; | |
5608 | case SECCAT_TDATA: | |
c711ba8e RH |
5609 | prefix = one_only ? ".gnu.linkonce.td." : ".tdata."; |
5610 | break; | |
ae46c4e0 | 5611 | case SECCAT_TBSS: |
c711ba8e RH |
5612 | prefix = one_only ? ".gnu.linkonce.tb." : ".tbss."; |
5613 | break; | |
ae46c4e0 | 5614 | default: |
fbc848cc | 5615 | gcc_unreachable (); |
ae46c4e0 RH |
5616 | } |
5617 | plen = strlen (prefix); | |
5618 | ||
5619 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
245f1bfa | 5620 | name = targetm.strip_name_encoding (name); |
ae46c4e0 RH |
5621 | nlen = strlen (name); |
5622 | ||
5623 | string = alloca (nlen + plen + 1); | |
5624 | memcpy (string, prefix, plen); | |
5625 | memcpy (string + plen, name, nlen + 1); | |
5626 | ||
5627 | DECL_SECTION_NAME (decl) = build_string (nlen + plen, string); | |
5628 | } | |
b64a1b53 | 5629 | |
d6b5193b | 5630 | section * |
2e1eedd6 AJ |
5631 | default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED, |
5632 | rtx x, | |
5633 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
b64a1b53 RH |
5634 | { |
5635 | if (flag_pic) | |
5636 | switch (GET_CODE (x)) | |
5637 | { | |
5638 | case CONST: | |
5639 | case SYMBOL_REF: | |
5640 | case LABEL_REF: | |
d6b5193b | 5641 | return data_section; |
b64a1b53 RH |
5642 | |
5643 | default: | |
5644 | break; | |
5645 | } | |
5646 | ||
d6b5193b | 5647 | return readonly_data_section; |
b64a1b53 RH |
5648 | } |
5649 | ||
d6b5193b | 5650 | section * |
2e1eedd6 AJ |
5651 | default_elf_select_rtx_section (enum machine_mode mode, rtx x, |
5652 | unsigned HOST_WIDE_INT align) | |
b64a1b53 RH |
5653 | { |
5654 | /* ??? Handle small data here somehow. */ | |
5655 | ||
5656 | if (flag_pic) | |
5657 | switch (GET_CODE (x)) | |
5658 | { | |
5659 | case CONST: | |
5660 | case SYMBOL_REF: | |
d6b5193b | 5661 | return get_named_section (NULL, ".data.rel.ro", 3); |
b64a1b53 RH |
5662 | |
5663 | case LABEL_REF: | |
d6b5193b | 5664 | return get_named_section (NULL, ".data.rel.ro.local", 1); |
b64a1b53 RH |
5665 | |
5666 | default: | |
5667 | break; | |
5668 | } | |
5669 | ||
d6b5193b | 5670 | return mergeable_constant_section (mode, align, 0); |
b64a1b53 | 5671 | } |
772c5265 | 5672 | |
52859c77 RH |
5673 | /* Set the generally applicable flags on the SYMBOL_REF for EXP. */ |
5674 | ||
5675 | void | |
2e1eedd6 | 5676 | default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED) |
52859c77 | 5677 | { |
c6a2438a | 5678 | rtx symbol; |
52859c77 RH |
5679 | int flags; |
5680 | ||
52859c77 | 5681 | /* Careful not to prod global register variables. */ |
3c0cb5de | 5682 | if (!MEM_P (rtl)) |
52859c77 RH |
5683 | return; |
5684 | symbol = XEXP (rtl, 0); | |
5685 | if (GET_CODE (symbol) != SYMBOL_REF) | |
5686 | return; | |
5687 | ||
3fa9c136 | 5688 | flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO; |
52859c77 RH |
5689 | if (TREE_CODE (decl) == FUNCTION_DECL) |
5690 | flags |= SYMBOL_FLAG_FUNCTION; | |
5fd9b178 | 5691 | if (targetm.binds_local_p (decl)) |
52859c77 | 5692 | flags |= SYMBOL_FLAG_LOCAL; |
c2f7fa15 SB |
5693 | if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)) |
5694 | flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT; | |
0050e862 AM |
5695 | else if (targetm.in_small_data_p (decl)) |
5696 | flags |= SYMBOL_FLAG_SMALL; | |
1b8135a4 RH |
5697 | /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without |
5698 | being PUBLIC, the thing *must* be defined in this translation unit. | |
5699 | Prevent this buglet from being propagated into rtl code as well. */ | |
5700 | if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)) | |
52859c77 RH |
5701 | flags |= SYMBOL_FLAG_EXTERNAL; |
5702 | ||
5703 | SYMBOL_REF_FLAGS (symbol) = flags; | |
5704 | } | |
5705 | ||
772c5265 RH |
5706 | /* By default, we do nothing for encode_section_info, so we need not |
5707 | do anything but discard the '*' marker. */ | |
5708 | ||
5709 | const char * | |
2e1eedd6 | 5710 | default_strip_name_encoding (const char *str) |
772c5265 RH |
5711 | { |
5712 | return str + (*str == '*'); | |
5713 | } | |
47754fd5 | 5714 | |
aacd3885 RS |
5715 | #ifdef ASM_OUTPUT_DEF |
5716 | /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the | |
5717 | anchor relative to ".", the current section position. */ | |
5718 | ||
5719 | void | |
5720 | default_asm_output_anchor (rtx symbol) | |
5721 | { | |
5722 | char buffer[100]; | |
5723 | ||
5724 | sprintf (buffer, ". + " HOST_WIDE_INT_PRINT_DEC, | |
5725 | SYMBOL_REF_BLOCK_OFFSET (symbol)); | |
5726 | ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer); | |
5727 | } | |
5728 | #endif | |
5729 | ||
5730 | /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */ | |
5731 | ||
5732 | bool | |
5733 | default_use_anchors_for_symbol_p (rtx symbol) | |
5734 | { | |
5735 | section *sect; | |
5736 | tree decl; | |
5737 | ||
5738 | /* Don't use anchors for mergeable sections. The linker might move | |
5739 | the objects around. */ | |
5740 | sect = SYMBOL_REF_BLOCK (symbol)->sect; | |
5741 | if (sect->common.flags & SECTION_MERGE) | |
5742 | return false; | |
5743 | ||
5744 | /* Don't use anchors for small data sections. The small data register | |
5745 | acts as an anchor for such sections. */ | |
5746 | if (sect->common.flags & SECTION_SMALL) | |
5747 | return false; | |
5748 | ||
5749 | decl = SYMBOL_REF_DECL (symbol); | |
5750 | if (decl && DECL_P (decl)) | |
5751 | { | |
5752 | /* Don't use section anchors for decls that might be defined by | |
5753 | other modules. */ | |
5754 | if (!targetm.binds_local_p (decl)) | |
5755 | return false; | |
5756 | ||
5757 | /* Don't use section anchors for decls that will be placed in a | |
5758 | small data section. */ | |
5759 | /* ??? Ideally, this check would be redundant with the SECTION_SMALL | |
5760 | one above. The problem is that we only use SECTION_SMALL for | |
5761 | sections that should be marked as small in the section directive. */ | |
5762 | if (targetm.in_small_data_p (decl)) | |
5763 | return false; | |
5764 | } | |
5765 | return true; | |
5766 | } | |
5767 | ||
47754fd5 RH |
5768 | /* Assume ELF-ish defaults, since that's pretty much the most liberal |
5769 | wrt cross-module name binding. */ | |
5770 | ||
5771 | bool | |
2e1eedd6 | 5772 | default_binds_local_p (tree exp) |
2cc9fb4c | 5773 | { |
24a4dd31 | 5774 | return default_binds_local_p_1 (exp, flag_shlib); |
2cc9fb4c DE |
5775 | } |
5776 | ||
5777 | bool | |
2e1eedd6 | 5778 | default_binds_local_p_1 (tree exp, int shlib) |
47754fd5 RH |
5779 | { |
5780 | bool local_p; | |
5781 | ||
5782 | /* A non-decl is an entry in the constant pool. */ | |
5783 | if (!DECL_P (exp)) | |
5784 | local_p = true; | |
a9b0b825 GK |
5785 | /* Weakrefs may not bind locally, even though the weakref itself is |
5786 | always static and therefore local. */ | |
5787 | else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp))) | |
5788 | local_p = false; | |
923c7cdf RH |
5789 | /* Static variables are always local. */ |
5790 | else if (! TREE_PUBLIC (exp)) | |
5791 | local_p = true; | |
a9b0b825 GK |
5792 | /* A variable is local if the user has said explicitly that it will |
5793 | be. */ | |
083cad55 | 5794 | else if (DECL_VISIBILITY_SPECIFIED (exp) |
a9b0b825 | 5795 | && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT) |
47754fd5 | 5796 | local_p = true; |
a9b0b825 | 5797 | /* Variables defined outside this object might not be local. */ |
47754fd5 RH |
5798 | else if (DECL_EXTERNAL (exp)) |
5799 | local_p = false; | |
a9b0b825 GK |
5800 | /* If defined in this object and visibility is not default, must be |
5801 | local. */ | |
d7afec4b ND |
5802 | else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT) |
5803 | local_p = true; | |
a9b0b825 GK |
5804 | /* Default visibility weak data can be overridden by a strong symbol |
5805 | in another module and so are not local. */ | |
5806 | else if (DECL_WEAK (exp)) | |
5807 | local_p = false; | |
47754fd5 RH |
5808 | /* If PIC, then assume that any global name can be overridden by |
5809 | symbols resolved from other modules. */ | |
2cc9fb4c | 5810 | else if (shlib) |
47754fd5 RH |
5811 | local_p = false; |
5812 | /* Uninitialized COMMON variable may be unified with symbols | |
5813 | resolved from other modules. */ | |
5814 | else if (DECL_COMMON (exp) | |
5815 | && (DECL_INITIAL (exp) == NULL | |
5816 | || DECL_INITIAL (exp) == error_mark_node)) | |
5817 | local_p = false; | |
5818 | /* Otherwise we're left with initialized (or non-common) global data | |
5819 | which is of necessity defined locally. */ | |
5820 | else | |
5821 | local_p = true; | |
5822 | ||
5823 | return local_p; | |
5824 | } | |
e2500fed | 5825 | |
4977bab6 | 5826 | /* Determine whether or not a pointer mode is valid. Assume defaults |
5bdc5878 | 5827 | of ptr_mode or Pmode - can be overridden. */ |
4977bab6 | 5828 | bool |
2e1eedd6 | 5829 | default_valid_pointer_mode (enum machine_mode mode) |
4977bab6 ZW |
5830 | { |
5831 | return (mode == ptr_mode || mode == Pmode); | |
5832 | } | |
5833 | ||
5eb99654 | 5834 | /* Default function to output code that will globalize a label. A |
f3b569ca | 5835 | target must define GLOBAL_ASM_OP or provide its own function to |
5eb99654 KG |
5836 | globalize a label. */ |
5837 | #ifdef GLOBAL_ASM_OP | |
5838 | void | |
2e1eedd6 | 5839 | default_globalize_label (FILE * stream, const char *name) |
5eb99654 KG |
5840 | { |
5841 | fputs (GLOBAL_ASM_OP, stream); | |
5842 | assemble_name (stream, name); | |
5843 | putc ('\n', stream); | |
5844 | } | |
5845 | #endif /* GLOBAL_ASM_OP */ | |
2e1eedd6 | 5846 | |
4746cf84 MA |
5847 | /* Default function to output a label for unwind information. The |
5848 | default is to do nothing. A target that needs nonlocal labels for | |
9cf737f8 | 5849 | unwind information must provide its own function to do this. */ |
4746cf84 MA |
5850 | void |
5851 | default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED, | |
5852 | tree decl ATTRIBUTE_UNUSED, | |
eeab4d81 | 5853 | int for_eh ATTRIBUTE_UNUSED, |
4746cf84 | 5854 | int empty ATTRIBUTE_UNUSED) |
083cad55 EC |
5855 | { |
5856 | } | |
5857 | ||
5858 | /* Default function to output a label to divide up the exception table. | |
5859 | The default is to do nothing. A target that needs/wants to divide | |
5860 | up the table must provide it's own function to do this. */ | |
5861 | void | |
5862 | default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED) | |
5863 | { | |
4746cf84 MA |
5864 | } |
5865 | ||
4977bab6 ZW |
5866 | /* This is how to output an internal numbered label where PREFIX is |
5867 | the class of label and LABELNO is the number within the class. */ | |
5868 | ||
5869 | void | |
2e1eedd6 AJ |
5870 | default_internal_label (FILE *stream, const char *prefix, |
5871 | unsigned long labelno) | |
4977bab6 ZW |
5872 | { |
5873 | char *const buf = alloca (40 + strlen (prefix)); | |
5874 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno); | |
57829bc4 | 5875 | ASM_OUTPUT_INTERNAL_LABEL (stream, buf); |
4977bab6 ZW |
5876 | } |
5877 | ||
1bc7c5b6 ZW |
5878 | /* This is the default behavior at the beginning of a file. It's |
5879 | controlled by two other target-hook toggles. */ | |
5880 | void | |
2e1eedd6 | 5881 | default_file_start (void) |
1bc7c5b6 ZW |
5882 | { |
5883 | if (targetm.file_start_app_off && !flag_verbose_asm) | |
5884 | fputs (ASM_APP_OFF, asm_out_file); | |
5885 | ||
5886 | if (targetm.file_start_file_directive) | |
5887 | output_file_directive (asm_out_file, main_input_filename); | |
5888 | } | |
5889 | ||
a5fe455b ZW |
5890 | /* This is a generic routine suitable for use as TARGET_ASM_FILE_END |
5891 | which emits a special section directive used to indicate whether or | |
5892 | not this object file needs an executable stack. This is primarily | |
5893 | a GNU extension to ELF but could be used on other targets. */ | |
6de9cd9a DN |
5894 | |
5895 | int trampolines_created; | |
5896 | ||
a5fe455b | 5897 | void |
2e1eedd6 | 5898 | file_end_indicate_exec_stack (void) |
a5fe455b ZW |
5899 | { |
5900 | unsigned int flags = SECTION_DEBUG; | |
5901 | if (trampolines_created) | |
5902 | flags |= SECTION_CODE; | |
5903 | ||
d6b5193b RS |
5904 | switch_to_section (get_section (".note.GNU-stack", flags, NULL)); |
5905 | } | |
5906 | ||
5907 | /* Output DIRECTIVE (a C string) followed by a newline. This is used as | |
5908 | a get_unnamed_section callback. */ | |
5909 | ||
5910 | void | |
5911 | output_section_asm_op (const void *directive) | |
5912 | { | |
5913 | fprintf (asm_out_file, "%s\n", (const char *) directive); | |
5914 | } | |
5915 | ||
5916 | /* Emit assembly code to switch to section NEW_SECTION. Do nothing if | |
5917 | the current section is NEW_SECTION. */ | |
5918 | ||
5919 | void | |
5920 | switch_to_section (section *new_section) | |
5921 | { | |
5922 | if (in_section == new_section) | |
5923 | return; | |
5924 | ||
5925 | if (new_section->common.flags & SECTION_FORGET) | |
5926 | in_section = NULL; | |
5927 | else | |
c543ca49 | 5928 | in_section = new_section; |
d6b5193b | 5929 | |
434aeebb | 5930 | switch (SECTION_STYLE (new_section)) |
d6b5193b | 5931 | { |
434aeebb | 5932 | case SECTION_NAMED: |
d6b5193b RS |
5933 | if (cfun |
5934 | && !cfun->unlikely_text_section_name | |
5935 | && strcmp (new_section->named.name, | |
5936 | UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0) | |
5937 | cfun->unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME; | |
5938 | ||
5939 | targetm.asm_out.named_section (new_section->named.name, | |
5940 | new_section->named.common.flags, | |
5941 | new_section->named.decl); | |
434aeebb RS |
5942 | break; |
5943 | ||
5944 | case SECTION_UNNAMED: | |
5945 | new_section->unnamed.callback (new_section->unnamed.data); | |
5946 | break; | |
5947 | ||
5948 | case SECTION_NOSWITCH: | |
5949 | gcc_unreachable (); | |
5950 | break; | |
d6b5193b | 5951 | } |
d6b5193b RS |
5952 | |
5953 | new_section->common.flags |= SECTION_DECLARED; | |
a5fe455b ZW |
5954 | } |
5955 | ||
aacd3885 RS |
5956 | /* If block symbol SYMBOL has not yet been assigned an offset, place |
5957 | it at the end of its block. */ | |
5958 | ||
5959 | void | |
5960 | place_block_symbol (rtx symbol) | |
5961 | { | |
5962 | unsigned HOST_WIDE_INT size, mask, offset; | |
5963 | struct constant_descriptor_rtx *desc; | |
5964 | unsigned int alignment; | |
5965 | struct object_block *block; | |
5966 | tree decl; | |
5967 | ||
434aeebb | 5968 | gcc_assert (SYMBOL_REF_BLOCK (symbol)); |
aacd3885 RS |
5969 | if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0) |
5970 | return; | |
5971 | ||
5972 | /* Work out the symbol's size and alignment. */ | |
5973 | if (CONSTANT_POOL_ADDRESS_P (symbol)) | |
5974 | { | |
5975 | desc = SYMBOL_REF_CONSTANT (symbol); | |
5976 | alignment = desc->align; | |
5977 | size = GET_MODE_SIZE (desc->mode); | |
5978 | } | |
5979 | else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol)) | |
5980 | { | |
5981 | decl = SYMBOL_REF_DECL (symbol); | |
5982 | alignment = get_constant_alignment (decl); | |
5983 | size = get_constant_size (decl); | |
5984 | } | |
5985 | else | |
5986 | { | |
5987 | decl = SYMBOL_REF_DECL (symbol); | |
5988 | alignment = DECL_ALIGN (decl); | |
5989 | size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); | |
5990 | } | |
5991 | ||
5992 | /* Calculate the object's offset from the start of the block. */ | |
5993 | block = SYMBOL_REF_BLOCK (symbol); | |
5994 | mask = alignment / BITS_PER_UNIT - 1; | |
5995 | offset = (block->size + mask) & ~mask; | |
5996 | SYMBOL_REF_BLOCK_OFFSET (symbol) = offset; | |
5997 | ||
5998 | /* Record the block's new alignment and size. */ | |
5999 | block->alignment = MAX (block->alignment, alignment); | |
6000 | block->size = offset + size; | |
6001 | ||
6002 | VEC_safe_push (rtx, gc, block->objects, symbol); | |
6003 | } | |
6004 | ||
6005 | /* Return the anchor that should be used to address byte offset OFFSET | |
6006 | from the first object in BLOCK. MODEL is the TLS model used | |
6007 | to access it. */ | |
6008 | ||
6009 | rtx | |
6010 | get_section_anchor (struct object_block *block, HOST_WIDE_INT offset, | |
6011 | enum tls_model model) | |
6012 | { | |
6013 | char label[100]; | |
6014 | unsigned int begin, middle, end; | |
6015 | unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta; | |
6016 | rtx anchor; | |
6017 | ||
6018 | /* Work out the anchor's offset. Use an offset of 0 for the first | |
6019 | anchor so that we don't pessimize the case where we take the address | |
6020 | of a variable at the beginning of the block. This is particularly | |
6021 | useful when a block has only one variable assigned to it. | |
6022 | ||
6023 | We try to place anchors RANGE bytes apart, so there can then be | |
6024 | anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of | |
6025 | a ptr_mode offset. With some target settings, the lowest such | |
6026 | anchor might be out of range for the lowest ptr_mode offset; | |
6027 | likewise the highest anchor for the highest offset. Use anchors | |
6028 | at the extreme ends of the ptr_mode range in such cases. | |
6029 | ||
6030 | All arithmetic uses unsigned integers in order to avoid | |
6031 | signed overflow. */ | |
6032 | max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset; | |
6033 | min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset; | |
6034 | range = max_offset - min_offset + 1; | |
6035 | if (range == 0) | |
6036 | offset = 0; | |
6037 | else | |
6038 | { | |
6039 | bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1); | |
6040 | if (offset < 0) | |
6041 | { | |
6042 | delta = -(unsigned HOST_WIDE_INT) offset + max_offset; | |
6043 | delta -= delta % range; | |
6044 | if (delta > bias) | |
6045 | delta = bias; | |
6046 | offset = (HOST_WIDE_INT) (-delta); | |
6047 | } | |
6048 | else | |
6049 | { | |
6050 | delta = (unsigned HOST_WIDE_INT) offset - min_offset; | |
6051 | delta -= delta % range; | |
6052 | if (delta > bias - 1) | |
6053 | delta = bias - 1; | |
6054 | offset = (HOST_WIDE_INT) delta; | |
6055 | } | |
6056 | } | |
6057 | ||
6058 | /* Do a binary search to see if there's already an anchor we can use. | |
6059 | Set BEGIN to the new anchor's index if not. */ | |
6060 | begin = 0; | |
6061 | end = VEC_length (rtx, block->anchors); | |
6062 | while (begin != end) | |
6063 | { | |
6064 | middle = (end + begin) / 2; | |
6065 | anchor = VEC_index (rtx, block->anchors, middle); | |
6066 | if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset) | |
6067 | end = middle; | |
6068 | else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset) | |
6069 | begin = middle + 1; | |
6070 | else if (SYMBOL_REF_TLS_MODEL (anchor) > model) | |
6071 | end = middle; | |
6072 | else if (SYMBOL_REF_TLS_MODEL (anchor) < model) | |
6073 | begin = middle + 1; | |
6074 | else | |
6075 | return anchor; | |
6076 | } | |
6077 | ||
6078 | /* Create a new anchor with a unique label. */ | |
6079 | ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++); | |
6080 | anchor = create_block_symbol (ggc_strdup (label), block, offset); | |
6081 | SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR; | |
6082 | SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT; | |
6083 | ||
6084 | /* Insert it at index BEGIN. */ | |
6085 | VEC_safe_insert (rtx, gc, block->anchors, begin, anchor); | |
6086 | return anchor; | |
6087 | } | |
6088 | ||
6089 | /* Output the objects in BLOCK. */ | |
6090 | ||
6091 | static void | |
6092 | output_object_block (struct object_block *block) | |
6093 | { | |
6094 | struct constant_descriptor_rtx *desc; | |
6095 | unsigned int i; | |
6096 | HOST_WIDE_INT offset; | |
6097 | tree decl; | |
6098 | rtx symbol; | |
6099 | ||
6100 | if (block->objects == NULL) | |
6101 | return; | |
6102 | ||
6103 | /* Switch to the section and make sure that the first byte is | |
6104 | suitably aligned. */ | |
6105 | switch_to_section (block->sect); | |
6106 | assemble_align (block->alignment); | |
6107 | ||
6108 | /* Define the values of all anchors relative to the current section | |
6109 | position. */ | |
6110 | for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++) | |
6111 | targetm.asm_out.output_anchor (symbol); | |
6112 | ||
6113 | /* Output the objects themselves. */ | |
6114 | offset = 0; | |
6115 | for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++) | |
6116 | { | |
6117 | /* Move to the object's offset, padding with zeros if necessary. */ | |
6118 | assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset); | |
6119 | offset = SYMBOL_REF_BLOCK_OFFSET (symbol); | |
6120 | if (CONSTANT_POOL_ADDRESS_P (symbol)) | |
6121 | { | |
6122 | desc = SYMBOL_REF_CONSTANT (symbol); | |
6123 | output_constant_pool_1 (desc, 1); | |
6124 | offset += GET_MODE_SIZE (desc->mode); | |
6125 | } | |
6126 | else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol)) | |
6127 | { | |
6128 | decl = SYMBOL_REF_DECL (symbol); | |
6129 | assemble_constant_contents (decl, XSTR (symbol, 0), | |
6130 | get_constant_alignment (decl)); | |
6131 | offset += get_constant_size (decl); | |
6132 | } | |
6133 | else | |
6134 | { | |
6135 | decl = SYMBOL_REF_DECL (symbol); | |
6136 | assemble_variable_contents (decl, XSTR (symbol, 0), false); | |
6137 | offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1); | |
6138 | } | |
6139 | } | |
6140 | } | |
6141 | ||
6142 | /* A htab_traverse callback used to call output_object_block for | |
6143 | each member of object_block_htab. */ | |
6144 | ||
6145 | static int | |
6146 | output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED) | |
6147 | { | |
6148 | output_object_block ((struct object_block *) (*slot)); | |
6149 | return 1; | |
6150 | } | |
6151 | ||
6152 | /* Output the definitions of all object_blocks. */ | |
6153 | ||
6154 | void | |
6155 | output_object_blocks (void) | |
6156 | { | |
6157 | htab_traverse (object_block_htab, output_object_block_htab, NULL); | |
6158 | } | |
6159 | ||
e2500fed | 6160 | #include "gt-varasm.h" |