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