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