]>
Commit | Line | Data |
---|---|---|
5243fbff | 1 | /* Output variables, constants and external declarations, for GNU compiler. |
b278476e | 2 | Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, |
cfaf579d | 3 | 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 |
64717bc5 | 4 | Free Software Foundation, Inc. |
5243fbff | 5 | |
f12b58b3 | 6 | This file is part of GCC. |
5243fbff | 7 | |
f12b58b3 | 8 | GCC is free software; you can redistribute it and/or modify it under |
9 | the terms of the GNU General Public License as published by the Free | |
8c4c00c1 | 10 | Software Foundation; either version 3, or (at your option) any later |
f12b58b3 | 11 | version. |
5243fbff | 12 | |
f12b58b3 | 13 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
14 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | for more details. | |
5243fbff | 17 | |
18 | You should have received a copy of the GNU General Public License | |
8c4c00c1 | 19 | along with GCC; see the file COPYING3. If not see |
20 | <http://www.gnu.org/licenses/>. */ | |
5243fbff | 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 | ||
0dbd1c74 | 30 | #include "config.h" |
405711de | 31 | #include "system.h" |
805e22b2 | 32 | #include "coretypes.h" |
33 | #include "tm.h" | |
5243fbff | 34 | #include "rtl.h" |
35 | #include "tree.h" | |
36 | #include "flags.h" | |
1cc10897 | 37 | #include "function.h" |
5243fbff | 38 | #include "expr.h" |
39 | #include "hard-reg-set.h" | |
40 | #include "regs.h" | |
dd88b4b1 | 41 | #include "real.h" |
ff603ed3 | 42 | #include "output.h" |
12874aaf | 43 | #include "toplev.h" |
abf74c5b | 44 | #include "hashtab.h" |
a7b0c170 | 45 | #include "ggc.h" |
b3187c7c | 46 | #include "langhooks.h" |
1dd6c958 | 47 | #include "tm_p.h" |
f76df888 | 48 | #include "debug.h" |
2cb4ac60 | 49 | #include "target.h" |
38475469 | 50 | #include "targhooks.h" |
4ee9c684 | 51 | #include "tree-mudflap.h" |
3d7bfc56 | 52 | #include "cgraph.h" |
4f18499c | 53 | #include "cfglayout.h" |
1897b881 | 54 | #include "basic-block.h" |
9dda1f80 | 55 | #include "tree-iterator.h" |
5243fbff | 56 | |
397c7bc7 | 57 | #ifdef XCOFF_DEBUGGING_INFO |
58 | #include "xcoffout.h" /* Needed for external data | |
59 | declarations for e.g. AIX 4.x. */ | |
60 | #endif | |
61 | ||
5243fbff | 62 | /* The (assembler) name of the first globally-visible object output. */ |
724ea712 | 63 | extern GTY(()) const char *first_global_object_name; |
64 | extern GTY(()) const char *weak_global_object_name; | |
65 | ||
e772a198 | 66 | const char *first_global_object_name; |
67 | const char *weak_global_object_name; | |
5243fbff | 68 | |
605f66ec | 69 | struct addr_const; |
1f3233d1 | 70 | struct constant_descriptor_rtx; |
01714e38 | 71 | struct rtx_constant_pool; |
605f66ec | 72 | |
fd6ffb7c | 73 | #define n_deferred_constants (crtl->varasm.deferred_constants) |
605f66ec | 74 | |
5243fbff | 75 | /* Number for making the label on the next |
76 | constant that is stored in memory. */ | |
77 | ||
573aba85 | 78 | static GTY(()) int const_labelno; |
5243fbff | 79 | |
a511b195 | 80 | /* Carry information from ASM_DECLARE_OBJECT_NAME |
81 | to ASM_FINISH_DECLARE_OBJECT. */ | |
82 | ||
83 | int size_directive_output; | |
84 | ||
14a4bf15 | 85 | /* The last decl for which assemble_variable was called, |
86 | if it did ASM_DECLARE_OBJECT_NAME. | |
87 | If the last call to assemble_variable didn't do that, | |
88 | this holds 0. */ | |
89 | ||
90 | tree last_assemble_variable_decl; | |
91 | ||
1897b881 | 92 | /* The following global variable indicates if the first basic block |
93 | in a function belongs to the cold partition or not. */ | |
4f18499c | 94 | |
1897b881 | 95 | bool first_function_block_is_cold; |
4f18499c | 96 | |
b04fab2a | 97 | /* We give all constants their own alias set. Perhaps redundant with |
98 | MEM_READONLY_P, but pre-dates it. */ | |
ebde4c17 | 99 | |
32c2fdea | 100 | static alias_set_type const_alias_set; |
ebde4c17 | 101 | |
3180a54f | 102 | static const char *strip_reg_name (const char *); |
103 | static int contains_pointers_p (tree); | |
73533af5 | 104 | #ifdef ASM_OUTPUT_EXTERNAL |
105 | static bool incorporeal_function_p (tree); | |
106 | #endif | |
3180a54f | 107 | static void decode_addr_const (tree, struct addr_const *); |
108 | static hashval_t const_desc_hash (const void *); | |
109 | static int const_desc_eq (const void *, const void *); | |
110 | static hashval_t const_hash_1 (const tree); | |
111 | static int compare_constant (const tree, const tree); | |
112 | static tree copy_constant (tree); | |
113 | static void output_constant_def_contents (rtx); | |
ee4722fe | 114 | static void output_addressed_constants (tree); |
3180a54f | 115 | static unsigned HOST_WIDE_INT array_size_for_constructor (tree); |
116 | static unsigned min_align (unsigned, unsigned); | |
3180a54f | 117 | static void globalize_decl (tree); |
473416c4 | 118 | #ifdef BSS_SECTION_ASM_OP |
2a43678b | 119 | #ifdef ASM_OUTPUT_BSS |
3180a54f | 120 | static void asm_output_bss (FILE *, tree, const char *, |
121 | unsigned HOST_WIDE_INT, unsigned HOST_WIDE_INT); | |
2a43678b | 122 | #endif |
123 | #ifdef ASM_OUTPUT_ALIGNED_BSS | |
3180a54f | 124 | static void asm_output_aligned_bss (FILE *, tree, const char *, |
125 | unsigned HOST_WIDE_INT, int) | |
126 | ATTRIBUTE_UNUSED; | |
2a43678b | 127 | #endif |
a986b5e0 | 128 | #endif /* BSS_SECTION_ASM_OP */ |
3180a54f | 129 | static void mark_weak (tree); |
372df111 | 130 | static void output_constant_pool (const char *, tree); |
5243fbff | 131 | \f |
2f14b1f9 | 132 | /* Well-known sections, each one associated with some sort of *_ASM_OP. */ |
133 | section *text_section; | |
134 | section *data_section; | |
135 | section *readonly_data_section; | |
136 | section *sdata_section; | |
137 | section *ctors_section; | |
138 | section *dtors_section; | |
139 | section *bss_section; | |
140 | section *sbss_section; | |
2f14b1f9 | 141 | |
102e3995 | 142 | /* Various forms of common section. All are guaranteed to be nonnull. */ |
143 | section *tls_comm_section; | |
144 | section *comm_section; | |
145 | section *lcomm_section; | |
146 | ||
147 | /* A SECTION_NOSWITCH section used for declaring global BSS variables. | |
148 | May be null. */ | |
149 | section *bss_noswitch_section; | |
150 | ||
2943ce06 | 151 | /* The section that holds the main exception table, when known. The section |
152 | is set either by the target's init_sections hook or by the first call to | |
153 | switch_to_exception_section. */ | |
2f14b1f9 | 154 | section *exception_section; |
155 | ||
2943ce06 | 156 | /* The section that holds the DWARF2 frame unwind information, when known. |
157 | The section is set either by the target's init_sections hook or by the | |
158 | first call to switch_to_eh_frame_section. */ | |
2f14b1f9 | 159 | section *eh_frame_section; |
160 | ||
161 | /* asm_out_file's current section. This is NULL if no section has yet | |
162 | been selected or if we lose track of what the current section is. */ | |
163 | section *in_section; | |
164 | ||
5fbee89d | 165 | /* True if code for the current function is currently being directed |
166 | at the cold section. */ | |
167 | bool in_cold_section_p; | |
2f14b1f9 | 168 | |
169 | /* A linked list of all the unnamed sections. */ | |
170 | static GTY(()) section *unnamed_sections; | |
5243fbff | 171 | |
f712a0dc | 172 | /* Return a nonzero value if DECL has a section attribute. */ |
afe79027 | 173 | #ifndef IN_NAMED_SECTION |
0b30896b | 174 | #define IN_NAMED_SECTION(DECL) \ |
175 | ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \ | |
176 | && DECL_SECTION_NAME (DECL) != NULL_TREE) | |
afe79027 | 177 | #endif |
b7fdac4b | 178 | |
2f14b1f9 | 179 | /* Hash table of named sections. */ |
180 | static GTY((param_is (section))) htab_t section_htab; | |
0b30896b | 181 | |
f2d0e9f1 | 182 | /* A table of object_blocks, indexed by section. */ |
183 | static GTY((param_is (struct object_block))) htab_t object_block_htab; | |
184 | ||
185 | /* The next number to use for internal anchor labels. */ | |
186 | static GTY(()) int anchor_labelno; | |
187 | ||
2dbdc48e | 188 | /* A pool of constants that can be shared between functions. */ |
189 | static GTY(()) struct rtx_constant_pool *shared_constant_pool; | |
190 | ||
9dda1f80 | 191 | /* TLS emulation. */ |
192 | ||
193 | static GTY ((if_marked ("tree_map_marked_p"), param_is (struct tree_map))) | |
194 | htab_t emutls_htab; | |
195 | static GTY (()) tree emutls_object_type; | |
38475469 | 196 | /* Emulated TLS objects have the TLS model TLS_MODEL_EMULATED. This |
197 | macro can be used on them to distinguish the control variable from | |
198 | the initialization template. */ | |
199 | #define DECL_EMUTLS_VAR_P(D) (TREE_TYPE (D) == emutls_object_type) | |
200 | ||
201 | #if !defined (NO_DOT_IN_LABEL) | |
202 | # define EMUTLS_SEPARATOR "." | |
203 | #elif !defined (NO_DOLLAR_IN_LABEL) | |
204 | # define EMUTLS_SEPARATOR "$" | |
9dda1f80 | 205 | #else |
38475469 | 206 | # define EMUTLS_SEPARATOR "_" |
9dda1f80 | 207 | #endif |
208 | ||
38475469 | 209 | /* Create an IDENTIFIER_NODE by prefixing PREFIX to the |
210 | IDENTIFIER_NODE NAME's name. */ | |
9dda1f80 | 211 | |
212 | static tree | |
38475469 | 213 | prefix_name (const char *prefix, tree name) |
9dda1f80 | 214 | { |
38475469 | 215 | unsigned plen = strlen (prefix); |
216 | unsigned nlen = strlen (IDENTIFIER_POINTER (name)); | |
45ba1503 | 217 | char *toname = (char *) alloca (plen + nlen + 1); |
38475469 | 218 | |
219 | memcpy (toname, prefix, plen); | |
220 | memcpy (toname + plen, IDENTIFIER_POINTER (name), nlen + 1); | |
9dda1f80 | 221 | |
222 | return get_identifier (toname); | |
223 | } | |
224 | ||
38475469 | 225 | /* Create an identifier for the struct __emutls_object, given an identifier |
226 | of the DECL_ASSEMBLY_NAME of the original object. */ | |
9dda1f80 | 227 | |
228 | static tree | |
38475469 | 229 | get_emutls_object_name (tree name) |
9dda1f80 | 230 | { |
38475469 | 231 | const char *prefix = (targetm.emutls.var_prefix |
232 | ? targetm.emutls.var_prefix | |
233 | : "__emutls_v" EMUTLS_SEPARATOR); | |
234 | return prefix_name (prefix, name); | |
235 | } | |
9dda1f80 | 236 | |
38475469 | 237 | tree |
238 | default_emutls_var_fields (tree type, tree *name ATTRIBUTE_UNUSED) | |
239 | { | |
240 | tree word_type_node, field, next_field; | |
241 | ||
e60a6f7b | 242 | field = build_decl (UNKNOWN_LOCATION, |
243 | FIELD_DECL, get_identifier ("__templ"), ptr_type_node); | |
9dda1f80 | 244 | DECL_CONTEXT (field) = type; |
245 | next_field = field; | |
38475469 | 246 | |
e60a6f7b | 247 | field = build_decl (UNKNOWN_LOCATION, |
248 | FIELD_DECL, get_identifier ("__offset"), | |
38475469 | 249 | ptr_type_node); |
9dda1f80 | 250 | DECL_CONTEXT (field) = type; |
251 | TREE_CHAIN (field) = next_field; | |
252 | next_field = field; | |
38475469 | 253 | |
9dda1f80 | 254 | word_type_node = lang_hooks.types.type_for_mode (word_mode, 1); |
e60a6f7b | 255 | field = build_decl (UNKNOWN_LOCATION, |
256 | FIELD_DECL, get_identifier ("__align"), | |
38475469 | 257 | word_type_node); |
9dda1f80 | 258 | DECL_CONTEXT (field) = type; |
259 | TREE_CHAIN (field) = next_field; | |
260 | next_field = field; | |
38475469 | 261 | |
e60a6f7b | 262 | field = build_decl (UNKNOWN_LOCATION, |
263 | FIELD_DECL, get_identifier ("__size"), word_type_node); | |
9dda1f80 | 264 | DECL_CONTEXT (field) = type; |
265 | TREE_CHAIN (field) = next_field; | |
266 | ||
38475469 | 267 | return field; |
268 | } | |
269 | ||
270 | /* Create the structure for struct __emutls_object. This should match the | |
271 | structure at the top of emutls.c, modulo the union there. */ | |
272 | ||
273 | static tree | |
274 | get_emutls_object_type (void) | |
275 | { | |
276 | tree type, type_name, field; | |
277 | ||
278 | type = emutls_object_type; | |
279 | if (type) | |
280 | return type; | |
281 | ||
282 | emutls_object_type = type = lang_hooks.types.make_type (RECORD_TYPE); | |
283 | type_name = NULL; | |
284 | field = targetm.emutls.var_fields (type, &type_name); | |
285 | if (!type_name) | |
286 | type_name = get_identifier ("__emutls_object"); | |
e60a6f7b | 287 | type_name = build_decl (UNKNOWN_LOCATION, |
288 | TYPE_DECL, type_name, type); | |
38475469 | 289 | TYPE_NAME (type) = type_name; |
9dda1f80 | 290 | TYPE_FIELDS (type) = field; |
291 | layout_type (type); | |
292 | ||
293 | return type; | |
294 | } | |
295 | ||
296 | /* Create a read-only variable like DECL, with the same DECL_INITIAL. | |
297 | This will be used for initializing the emulated tls data area. */ | |
298 | ||
299 | static tree | |
300 | get_emutls_init_templ_addr (tree decl) | |
301 | { | |
302 | tree name, to; | |
38475469 | 303 | |
304 | if (targetm.emutls.register_common && !DECL_INITIAL (decl) | |
305 | && !DECL_SECTION_NAME (decl)) | |
9dda1f80 | 306 | return null_pointer_node; |
307 | ||
308 | name = DECL_ASSEMBLER_NAME (decl); | |
38475469 | 309 | if (!targetm.emutls.tmpl_prefix || targetm.emutls.tmpl_prefix[0]) |
310 | { | |
311 | const char *prefix = (targetm.emutls.tmpl_prefix | |
312 | ? targetm.emutls.tmpl_prefix | |
313 | : "__emutls_t" EMUTLS_SEPARATOR); | |
314 | name = prefix_name (prefix, name); | |
315 | } | |
9dda1f80 | 316 | |
e60a6f7b | 317 | to = build_decl (DECL_SOURCE_LOCATION (decl), |
318 | VAR_DECL, name, TREE_TYPE (decl)); | |
9dda1f80 | 319 | SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to)); |
38475469 | 320 | DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED; |
9dda1f80 | 321 | DECL_ARTIFICIAL (to) = 1; |
322 | TREE_USED (to) = TREE_USED (decl); | |
323 | TREE_READONLY (to) = 1; | |
324 | DECL_IGNORED_P (to) = 1; | |
325 | DECL_CONTEXT (to) = DECL_CONTEXT (decl); | |
38475469 | 326 | DECL_SECTION_NAME (to) = DECL_SECTION_NAME (decl); |
327 | ||
9dda1f80 | 328 | DECL_WEAK (to) = DECL_WEAK (decl); |
329 | if (DECL_ONE_ONLY (decl)) | |
330 | { | |
ecd88073 | 331 | make_decl_one_only (to, DECL_ASSEMBLER_NAME (to)); |
9dda1f80 | 332 | TREE_STATIC (to) = TREE_STATIC (decl); |
333 | TREE_PUBLIC (to) = TREE_PUBLIC (decl); | |
334 | DECL_VISIBILITY (to) = DECL_VISIBILITY (decl); | |
335 | } | |
336 | else | |
337 | TREE_STATIC (to) = 1; | |
338 | ||
339 | DECL_INITIAL (to) = DECL_INITIAL (decl); | |
340 | DECL_INITIAL (decl) = NULL; | |
341 | ||
342 | varpool_finalize_decl (to); | |
343 | return build_fold_addr_expr (to); | |
344 | } | |
345 | ||
346 | /* When emulating tls, we use a control structure for use by the runtime. | |
347 | Create and return this structure. */ | |
348 | ||
349 | tree | |
350 | emutls_decl (tree decl) | |
351 | { | |
352 | tree name, to; | |
353 | struct tree_map *h, in; | |
354 | void **loc; | |
355 | ||
356 | if (targetm.have_tls || decl == NULL || decl == error_mark_node | |
357 | || TREE_CODE (decl) != VAR_DECL || ! DECL_THREAD_LOCAL_P (decl)) | |
358 | return decl; | |
359 | ||
360 | /* Look up the object in the hash; return the control structure if | |
361 | it has already been created. */ | |
362 | if (! emutls_htab) | |
363 | emutls_htab = htab_create_ggc (512, tree_map_hash, tree_map_eq, 0); | |
364 | ||
365 | name = DECL_ASSEMBLER_NAME (decl); | |
366 | ||
367 | /* Note that we use the hash of the decl's name, rather than a hash | |
368 | of the decl's pointer. In emutls_finish we iterate through the | |
369 | hash table, and we want this traversal to be predictable. */ | |
370 | in.hash = htab_hash_string (IDENTIFIER_POINTER (name)); | |
9af7fd5b | 371 | in.base.from = decl; |
9dda1f80 | 372 | loc = htab_find_slot_with_hash (emutls_htab, &in, in.hash, INSERT); |
45ba1503 | 373 | h = (struct tree_map *) *loc; |
9dda1f80 | 374 | if (h != NULL) |
375 | to = h->to; | |
376 | else | |
377 | { | |
e60a6f7b | 378 | to = build_decl (DECL_SOURCE_LOCATION (decl), |
379 | VAR_DECL, get_emutls_object_name (name), | |
9dda1f80 | 380 | get_emutls_object_type ()); |
381 | ||
45ba1503 | 382 | h = GGC_NEW (struct tree_map); |
9dda1f80 | 383 | h->hash = in.hash; |
9af7fd5b | 384 | h->base.from = decl; |
9dda1f80 | 385 | h->to = to; |
386 | *(struct tree_map **) loc = h; | |
387 | ||
38475469 | 388 | DECL_TLS_MODEL (to) = TLS_MODEL_EMULATED; |
9dda1f80 | 389 | DECL_ARTIFICIAL (to) = 1; |
390 | DECL_IGNORED_P (to) = 1; | |
391 | TREE_READONLY (to) = 0; | |
9dda1f80 | 392 | SET_DECL_ASSEMBLER_NAME (to, DECL_NAME (to)); |
393 | if (DECL_ONE_ONLY (decl)) | |
ecd88073 | 394 | make_decl_one_only (to, DECL_ASSEMBLER_NAME (to)); |
9dda1f80 | 395 | DECL_CONTEXT (to) = DECL_CONTEXT (decl); |
38475469 | 396 | if (targetm.emutls.var_align_fixed) |
397 | /* If we're not allowed to change the proxy object's | |
398 | alignment, pretend it's been set by the user. */ | |
399 | DECL_USER_ALIGN (to) = 1; | |
9dda1f80 | 400 | } |
401 | ||
402 | /* Note that these fields may need to be updated from time to time from | |
403 | the original decl. Consider: | |
404 | extern __thread int i; | |
405 | int foo() { return i; } | |
406 | __thread int i = 1; | |
407 | in which I goes from external to locally defined and initialized. */ | |
408 | ||
409 | TREE_STATIC (to) = TREE_STATIC (decl); | |
410 | TREE_USED (to) = TREE_USED (decl); | |
411 | TREE_PUBLIC (to) = TREE_PUBLIC (decl); | |
412 | DECL_EXTERNAL (to) = DECL_EXTERNAL (decl); | |
413 | DECL_COMMON (to) = DECL_COMMON (decl); | |
414 | DECL_WEAK (to) = DECL_WEAK (decl); | |
415 | DECL_VISIBILITY (to) = DECL_VISIBILITY (decl); | |
416 | ||
417 | return to; | |
418 | } | |
419 | ||
420 | static int | |
421 | emutls_common_1 (void **loc, void *xstmts) | |
422 | { | |
423 | struct tree_map *h = *(struct tree_map **) loc; | |
424 | tree args, x, *pstmts = (tree *) xstmts; | |
425 | tree word_type_node; | |
426 | ||
9af7fd5b | 427 | if (! DECL_COMMON (h->base.from) |
428 | || (DECL_INITIAL (h->base.from) | |
429 | && DECL_INITIAL (h->base.from) != error_mark_node)) | |
9dda1f80 | 430 | return 1; |
431 | ||
432 | word_type_node = lang_hooks.types.type_for_mode (word_mode, 1); | |
433 | ||
434 | /* The idea was to call get_emutls_init_templ_addr here, but if we | |
435 | do this and there is an initializer, -fanchor_section loses, | |
436 | because it would be too late to ensure the template is | |
437 | output. */ | |
438 | x = null_pointer_node; | |
439 | args = tree_cons (NULL, x, NULL); | |
9af7fd5b | 440 | x = build_int_cst (word_type_node, DECL_ALIGN_UNIT (h->base.from)); |
9dda1f80 | 441 | args = tree_cons (NULL, x, args); |
9af7fd5b | 442 | x = fold_convert (word_type_node, DECL_SIZE_UNIT (h->base.from)); |
9dda1f80 | 443 | args = tree_cons (NULL, x, args); |
444 | x = build_fold_addr_expr (h->to); | |
445 | args = tree_cons (NULL, x, args); | |
446 | ||
447 | x = built_in_decls[BUILT_IN_EMUTLS_REGISTER_COMMON]; | |
448 | x = build_function_call_expr (x, args); | |
449 | ||
450 | append_to_statement_list (x, pstmts); | |
451 | return 1; | |
452 | } | |
453 | ||
454 | void | |
455 | emutls_finish (void) | |
456 | { | |
1f6a423f | 457 | if (targetm.emutls.register_common) |
38475469 | 458 | { |
459 | tree body = NULL_TREE; | |
9dda1f80 | 460 | |
38475469 | 461 | if (emutls_htab == NULL) |
462 | return; | |
9dda1f80 | 463 | |
38475469 | 464 | htab_traverse_noresize (emutls_htab, emutls_common_1, &body); |
465 | if (body == NULL_TREE) | |
466 | return; | |
467 | ||
468 | cgraph_build_static_cdtor ('I', body, DEFAULT_INIT_PRIORITY); | |
469 | } | |
9dda1f80 | 470 | } |
471 | ||
2f14b1f9 | 472 | /* Helper routines for maintaining section_htab. */ |
29a0ebee | 473 | |
2f14b1f9 | 474 | static int |
475 | section_entry_eq (const void *p1, const void *p2) | |
29a0ebee | 476 | { |
45ba1503 | 477 | const section *old = (const section *) p1; |
c32319fc | 478 | const char *new_name = (const char *) p2; |
29a0ebee | 479 | |
c32319fc | 480 | return strcmp (old->named.name, new_name) == 0; |
2f14b1f9 | 481 | } |
29a0ebee | 482 | |
2f14b1f9 | 483 | static hashval_t |
484 | section_entry_hash (const void *p) | |
485 | { | |
45ba1503 | 486 | const section *old = (const section *) p; |
2f14b1f9 | 487 | return htab_hash_string (old->named.name); |
488 | } | |
489 | ||
f2d0e9f1 | 490 | /* Return a hash value for section SECT. */ |
491 | ||
492 | static hashval_t | |
493 | hash_section (section *sect) | |
494 | { | |
495 | if (sect->common.flags & SECTION_NAMED) | |
496 | return htab_hash_string (sect->named.name); | |
497 | return sect->common.flags; | |
498 | } | |
499 | ||
500 | /* Helper routines for maintaining object_block_htab. */ | |
501 | ||
502 | static int | |
503 | object_block_entry_eq (const void *p1, const void *p2) | |
504 | { | |
45ba1503 | 505 | const struct object_block *old = (const struct object_block *) p1; |
c32319fc | 506 | const section *new_section = (const section *) p2; |
f2d0e9f1 | 507 | |
c32319fc | 508 | return old->sect == new_section; |
f2d0e9f1 | 509 | } |
510 | ||
511 | static hashval_t | |
512 | object_block_entry_hash (const void *p) | |
513 | { | |
45ba1503 | 514 | const struct object_block *old = (const struct object_block *) p; |
f2d0e9f1 | 515 | return hash_section (old->sect); |
516 | } | |
517 | ||
2f14b1f9 | 518 | /* Return a new unnamed section with the given fields. */ |
519 | ||
520 | section * | |
521 | get_unnamed_section (unsigned int flags, void (*callback) (const void *), | |
522 | const void *data) | |
523 | { | |
524 | section *sect; | |
525 | ||
c768b48b | 526 | sect = GGC_NEW (section); |
102e3995 | 527 | sect->unnamed.common.flags = flags | SECTION_UNNAMED; |
2f14b1f9 | 528 | sect->unnamed.callback = callback; |
529 | sect->unnamed.data = data; | |
530 | sect->unnamed.next = unnamed_sections; | |
531 | ||
532 | unnamed_sections = sect; | |
533 | return sect; | |
534 | } | |
535 | ||
102e3995 | 536 | /* Return a SECTION_NOSWITCH section with the given fields. */ |
537 | ||
538 | static section * | |
539 | get_noswitch_section (unsigned int flags, noswitch_section_callback callback) | |
540 | { | |
541 | section *sect; | |
542 | ||
c768b48b | 543 | sect = GGC_NEW (section); |
102e3995 | 544 | sect->noswitch.common.flags = flags | SECTION_NOSWITCH; |
545 | sect->noswitch.callback = callback; | |
546 | ||
547 | return sect; | |
548 | } | |
549 | ||
2f14b1f9 | 550 | /* Return the named section structure associated with NAME. Create |
551 | a new section with the given fields if no such structure exists. */ | |
552 | ||
553 | section * | |
554 | get_section (const char *name, unsigned int flags, tree decl) | |
555 | { | |
556 | section *sect, **slot; | |
557 | ||
558 | slot = (section **) | |
559 | htab_find_slot_with_hash (section_htab, name, | |
560 | htab_hash_string (name), INSERT); | |
2943ce06 | 561 | flags |= SECTION_NAMED; |
2f14b1f9 | 562 | if (*slot == NULL) |
563 | { | |
c768b48b | 564 | sect = GGC_NEW (section); |
2943ce06 | 565 | sect->named.common.flags = flags; |
2f14b1f9 | 566 | sect->named.name = ggc_strdup (name); |
567 | sect->named.decl = decl; | |
568 | *slot = sect; | |
569 | } | |
570 | else | |
571 | { | |
572 | sect = *slot; | |
2943ce06 | 573 | if ((sect->common.flags & ~SECTION_DECLARED) != flags |
2f14b1f9 | 574 | && ((sect->common.flags | flags) & SECTION_OVERRIDE) == 0) |
575 | { | |
576 | /* Sanity check user variables for flag changes. */ | |
577 | if (decl == 0) | |
578 | decl = sect->named.decl; | |
120ad03d | 579 | gcc_assert (decl); |
580 | error ("%+D causes a section type conflict", decl); | |
2f14b1f9 | 581 | } |
582 | } | |
583 | return sect; | |
584 | } | |
5243fbff | 585 | |
f2d0e9f1 | 586 | /* Return true if the current compilation mode benefits from having |
587 | objects grouped into blocks. */ | |
588 | ||
589 | static bool | |
590 | use_object_blocks_p (void) | |
591 | { | |
592 | return flag_section_anchors; | |
593 | } | |
594 | ||
595 | /* Return the object_block structure for section SECT. Create a new | |
102e3995 | 596 | structure if we haven't created one already. Return null if SECT |
597 | itself is null. */ | |
f2d0e9f1 | 598 | |
599 | static struct object_block * | |
600 | get_block_for_section (section *sect) | |
601 | { | |
602 | struct object_block *block; | |
603 | void **slot; | |
604 | ||
102e3995 | 605 | if (sect == NULL) |
606 | return NULL; | |
607 | ||
f2d0e9f1 | 608 | slot = htab_find_slot_with_hash (object_block_htab, sect, |
609 | hash_section (sect), INSERT); | |
610 | block = (struct object_block *) *slot; | |
611 | if (block == NULL) | |
612 | { | |
613 | block = (struct object_block *) | |
614 | ggc_alloc_cleared (sizeof (struct object_block)); | |
615 | block->sect = sect; | |
616 | *slot = block; | |
617 | } | |
618 | return block; | |
619 | } | |
620 | ||
621 | /* Create a symbol with label LABEL and place it at byte offset | |
622 | OFFSET in BLOCK. OFFSET can be negative if the symbol's offset | |
623 | is not yet known. LABEL must be a garbage-collected string. */ | |
624 | ||
625 | static rtx | |
626 | create_block_symbol (const char *label, struct object_block *block, | |
627 | HOST_WIDE_INT offset) | |
628 | { | |
629 | rtx symbol; | |
630 | unsigned int size; | |
631 | ||
632 | /* Create the extended SYMBOL_REF. */ | |
633 | size = RTX_HDR_SIZE + sizeof (struct block_symbol); | |
45ba1503 | 634 | symbol = (rtx) ggc_alloc_zone (size, &rtl_zone); |
f2d0e9f1 | 635 | |
636 | /* Initialize the normal SYMBOL_REF fields. */ | |
637 | memset (symbol, 0, size); | |
638 | PUT_CODE (symbol, SYMBOL_REF); | |
639 | PUT_MODE (symbol, Pmode); | |
640 | XSTR (symbol, 0) = label; | |
6617cbc1 | 641 | SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_HAS_BLOCK_INFO; |
f2d0e9f1 | 642 | |
643 | /* Initialize the block_symbol stuff. */ | |
644 | SYMBOL_REF_BLOCK (symbol) = block; | |
645 | SYMBOL_REF_BLOCK_OFFSET (symbol) = offset; | |
646 | ||
647 | return symbol; | |
648 | } | |
649 | ||
1897b881 | 650 | static void |
651 | initialize_cold_section_name (void) | |
4f18499c | 652 | { |
4d0e931f | 653 | const char *stripped_name; |
b90d852a | 654 | char *name, *buffer; |
655 | tree dsn; | |
065efcb1 | 656 | |
792a073a | 657 | gcc_assert (cfun && current_function_decl); |
abe32cce | 658 | if (crtl->subsections.unlikely_text_section_name) |
792a073a | 659 | return; |
660 | ||
b90d852a | 661 | dsn = DECL_SECTION_NAME (current_function_decl); |
662 | if (flag_function_sections && dsn) | |
4f18499c | 663 | { |
45ba1503 | 664 | name = (char *) alloca (TREE_STRING_LENGTH (dsn) + 1); |
b90d852a | 665 | memcpy (name, TREE_STRING_POINTER (dsn), TREE_STRING_LENGTH (dsn) + 1); |
666 | ||
792a073a | 667 | stripped_name = targetm.strip_name_encoding (name); |
b90d852a | 668 | |
792a073a | 669 | buffer = ACONCAT ((stripped_name, "_unlikely", NULL)); |
abe32cce | 670 | crtl->subsections.unlikely_text_section_name = ggc_strdup (buffer); |
1897b881 | 671 | } |
4d0e931f | 672 | else |
abe32cce | 673 | crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME; |
1897b881 | 674 | } |
675 | ||
1897b881 | 676 | /* Tell assembler to switch to unlikely-to-be-executed text section. */ |
677 | ||
2f14b1f9 | 678 | section * |
1897b881 | 679 | unlikely_text_section (void) |
680 | { | |
4d0e931f | 681 | if (cfun) |
682 | { | |
abe32cce | 683 | if (!crtl->subsections.unlikely_text_section_name) |
4d0e931f | 684 | initialize_cold_section_name (); |
065efcb1 | 685 | |
abe32cce | 686 | return get_named_section (NULL, crtl->subsections.unlikely_text_section_name, 0); |
4d0e931f | 687 | } |
688 | else | |
2f14b1f9 | 689 | return get_named_section (NULL, UNLIKELY_EXECUTED_TEXT_SECTION_NAME, 0); |
bbc5a1b5 | 690 | } |
d78bba10 | 691 | |
2f14b1f9 | 692 | /* When called within a function context, return true if the function |
693 | has been assigned a cold text section and if SECT is that section. | |
694 | When called outside a function context, return true if SECT is the | |
695 | default cold section. */ | |
5cdb6d31 | 696 | |
697 | bool | |
2f14b1f9 | 698 | unlikely_text_section_p (section *sect) |
5cdb6d31 | 699 | { |
2f14b1f9 | 700 | const char *name; |
5cdb6d31 | 701 | |
2f14b1f9 | 702 | if (cfun) |
abe32cce | 703 | name = crtl->subsections.unlikely_text_section_name; |
bc70bd5e | 704 | else |
2f14b1f9 | 705 | name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME; |
29a0ebee | 706 | |
2f14b1f9 | 707 | return (name |
708 | && sect | |
102e3995 | 709 | && SECTION_STYLE (sect) == SECTION_NAMED |
2f14b1f9 | 710 | && strcmp (name, sect->named.name) == 0); |
29a0ebee | 711 | } |
712 | ||
2f14b1f9 | 713 | /* Return a section with a particular name and with whatever SECTION_* |
714 | flags section_type_flags deems appropriate. The name of the section | |
715 | is taken from NAME if nonnull, otherwise it is taken from DECL's | |
716 | DECL_SECTION_NAME. DECL is the decl associated with the section | |
717 | (see the section comment for details) and RELOC is as for | |
718 | section_type_flags. */ | |
2cb4ac60 | 719 | |
2f14b1f9 | 720 | section * |
721 | get_named_section (tree decl, const char *name, int reloc) | |
0b30896b | 722 | { |
2cb4ac60 | 723 | unsigned int flags; |
724 | ||
22167fd5 | 725 | gcc_assert (!decl || DECL_P (decl)); |
cd48e72a | 726 | if (name == NULL) |
727 | name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
728 | ||
6fb33aa0 | 729 | flags = targetm.section_type_flags (decl, name, reloc); |
29a0ebee | 730 | |
2f14b1f9 | 731 | return get_section (name, flags, decl); |
2cb4ac60 | 732 | } |
0dbd1c74 | 733 | |
2cb4ac60 | 734 | /* If required, set DECL_SECTION_NAME to a unique name. */ |
735 | ||
d7bec695 | 736 | void |
3180a54f | 737 | resolve_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED, |
738 | int flag_function_or_data_sections) | |
2cb4ac60 | 739 | { |
740 | if (DECL_SECTION_NAME (decl) == NULL_TREE | |
52470889 | 741 | && targetm.have_named_sections |
6ccd54fd | 742 | && (flag_function_or_data_sections |
52470889 | 743 | || DECL_ONE_ONLY (decl))) |
883b2e73 | 744 | targetm.asm_out.unique_section (decl, reloc); |
0b30896b | 745 | } |
b409d58e | 746 | |
b0d70662 | 747 | #ifdef BSS_SECTION_ASM_OP |
748 | ||
b0d70662 | 749 | #ifdef ASM_OUTPUT_BSS |
750 | ||
751 | /* Utility function for ASM_OUTPUT_BSS for targets to use if | |
752 | they don't support alignments in .bss. | |
753 | ??? It is believed that this function will work in most cases so such | |
754 | support is localized here. */ | |
755 | ||
756 | static void | |
3180a54f | 757 | asm_output_bss (FILE *file, tree decl ATTRIBUTE_UNUSED, |
758 | const char *name, | |
759 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
760 | unsigned HOST_WIDE_INT rounded) | |
b0d70662 | 761 | { |
9afff52d | 762 | gcc_assert (strcmp (XSTR (XEXP (DECL_RTL (decl), 0), 0), name) == 0); |
763 | targetm.asm_out.globalize_decl_name (file, decl); | |
2f14b1f9 | 764 | switch_to_section (bss_section); |
f9109f75 | 765 | #ifdef ASM_DECLARE_OBJECT_NAME |
766 | last_assemble_variable_decl = decl; | |
767 | ASM_DECLARE_OBJECT_NAME (file, name, decl); | |
768 | #else | |
769 | /* Standard thing is just output label for the object. */ | |
b0d70662 | 770 | ASM_OUTPUT_LABEL (file, name); |
f9109f75 | 771 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
99c46869 | 772 | ASM_OUTPUT_SKIP (file, rounded ? rounded : 1); |
b0d70662 | 773 | } |
774 | ||
775 | #endif | |
776 | ||
777 | #ifdef ASM_OUTPUT_ALIGNED_BSS | |
778 | ||
779 | /* Utility function for targets to use in implementing | |
780 | ASM_OUTPUT_ALIGNED_BSS. | |
781 | ??? It is believed that this function will work in most cases so such | |
782 | support is localized here. */ | |
783 | ||
784 | static void | |
3180a54f | 785 | asm_output_aligned_bss (FILE *file, tree decl ATTRIBUTE_UNUSED, |
786 | const char *name, unsigned HOST_WIDE_INT size, | |
787 | int align) | |
b0d70662 | 788 | { |
2f14b1f9 | 789 | switch_to_section (bss_section); |
b0d70662 | 790 | ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT)); |
f9109f75 | 791 | #ifdef ASM_DECLARE_OBJECT_NAME |
792 | last_assemble_variable_decl = decl; | |
793 | ASM_DECLARE_OBJECT_NAME (file, name, decl); | |
794 | #else | |
795 | /* Standard thing is just output label for the object. */ | |
b0d70662 | 796 | ASM_OUTPUT_LABEL (file, name); |
f9109f75 | 797 | #endif /* ASM_DECLARE_OBJECT_NAME */ |
2d5ecab6 | 798 | ASM_OUTPUT_SKIP (file, size ? size : 1); |
b0d70662 | 799 | } |
800 | ||
801 | #endif | |
802 | ||
803 | #endif /* BSS_SECTION_ASM_OP */ | |
804 | ||
5fbee89d | 805 | #ifndef USE_SELECT_SECTION_FOR_FUNCTIONS |
806 | /* Return the hot section for function DECL. Return text_section for | |
807 | null DECLs. */ | |
808 | ||
809 | static section * | |
810 | hot_function_section (tree decl) | |
811 | { | |
812 | if (decl != NULL_TREE | |
813 | && DECL_SECTION_NAME (decl) != NULL_TREE | |
814 | && targetm.have_named_sections) | |
815 | return get_named_section (decl, NULL, 0); | |
816 | else | |
817 | return text_section; | |
818 | } | |
819 | #endif | |
820 | ||
2f14b1f9 | 821 | /* Return the section for function DECL. |
b409d58e | 822 | |
2f14b1f9 | 823 | If DECL is NULL_TREE, return the text section. We can be passed |
3e20eb32 | 824 | NULL_TREE under some circumstances by dbxout.c at least. */ |
b409d58e | 825 | |
2f14b1f9 | 826 | section * |
3180a54f | 827 | function_section (tree decl) |
b409d58e | 828 | { |
4d0e931f | 829 | int reloc = 0; |
b215c058 | 830 | |
1897b881 | 831 | if (first_function_block_is_cold) |
4d0e931f | 832 | reloc = 1; |
b215c058 | 833 | |
1897b881 | 834 | #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS |
6d7204c3 | 835 | if (decl != NULL_TREE |
836 | && DECL_SECTION_NAME (decl) != NULL_TREE) | |
837 | return reloc ? unlikely_text_section () | |
838 | : get_named_section (decl, NULL, 0); | |
839 | else | |
840 | return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl)); | |
1897b881 | 841 | #else |
6d7204c3 | 842 | return reloc ? unlikely_text_section () : hot_function_section (decl); |
1897b881 | 843 | #endif |
844 | } | |
3e20eb32 | 845 | |
2f14b1f9 | 846 | section * |
847 | current_function_section (void) | |
1897b881 | 848 | { |
1dc74225 | 849 | #ifdef USE_SELECT_SECTION_FOR_FUNCTIONS |
6d7204c3 | 850 | if (current_function_decl != NULL_TREE |
851 | && DECL_SECTION_NAME (current_function_decl) != NULL_TREE) | |
852 | return in_cold_section_p ? unlikely_text_section () | |
853 | : get_named_section (current_function_decl, | |
854 | NULL, 0); | |
855 | else | |
856 | return targetm.asm_out.select_section (current_function_decl, | |
857 | in_cold_section_p, | |
858 | DECL_ALIGN (current_function_decl)); | |
1dc74225 | 859 | #else |
5fbee89d | 860 | return (in_cold_section_p |
861 | ? unlikely_text_section () | |
862 | : hot_function_section (current_function_decl)); | |
1dc74225 | 863 | #endif |
b409d58e | 864 | } |
ff55ffc7 | 865 | |
2f14b1f9 | 866 | /* Return the read-only data section associated with function DECL. */ |
76aec42f | 867 | |
2f14b1f9 | 868 | section * |
76aec42f | 869 | default_function_rodata_section (tree decl) |
870 | { | |
871 | if (decl != NULL_TREE && DECL_SECTION_NAME (decl)) | |
872 | { | |
873 | const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
874 | ||
2593b9be | 875 | if (DECL_ONE_ONLY (decl) && HAVE_COMDAT_GROUP) |
876 | { | |
b5240a18 | 877 | const char *dot; |
ac2a837e | 878 | size_t len; |
879 | char* rname; | |
880 | ||
881 | dot = strchr (name + 1, '.'); | |
882 | if (!dot) | |
883 | dot = name; | |
884 | len = strlen (dot) + 8; | |
885 | rname = (char *) alloca (len); | |
b215c058 | 886 | |
2593b9be | 887 | strcpy (rname, ".rodata"); |
ac2a837e | 888 | strcat (rname, dot); |
2f14b1f9 | 889 | return get_section (rname, SECTION_LINKONCE, decl); |
2593b9be | 890 | } |
76aec42f | 891 | /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */ |
2593b9be | 892 | else if (DECL_ONE_ONLY (decl) |
893 | && strncmp (name, ".gnu.linkonce.t.", 16) == 0) | |
76aec42f | 894 | { |
895 | size_t len = strlen (name) + 1; | |
45ba1503 | 896 | char *rname = (char *) alloca (len); |
76aec42f | 897 | |
898 | memcpy (rname, name, len); | |
899 | rname[14] = 'r'; | |
2f14b1f9 | 900 | return get_section (rname, SECTION_LINKONCE, decl); |
76aec42f | 901 | } |
902 | /* For .text.foo we want to use .rodata.foo. */ | |
903 | else if (flag_function_sections && flag_data_sections | |
904 | && strncmp (name, ".text.", 6) == 0) | |
905 | { | |
906 | size_t len = strlen (name) + 1; | |
45ba1503 | 907 | char *rname = (char *) alloca (len + 2); |
76aec42f | 908 | |
909 | memcpy (rname, ".rodata", 7); | |
910 | memcpy (rname + 7, name + 5, len - 5); | |
2f14b1f9 | 911 | return get_section (rname, 0, decl); |
76aec42f | 912 | } |
913 | } | |
914 | ||
2f14b1f9 | 915 | return readonly_data_section; |
76aec42f | 916 | } |
917 | ||
2f14b1f9 | 918 | /* Return the read-only data section associated with function DECL |
76aec42f | 919 | for targets where that section should be always the single |
920 | readonly data section. */ | |
921 | ||
2f14b1f9 | 922 | section * |
76aec42f | 923 | default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED) |
924 | { | |
2f14b1f9 | 925 | return readonly_data_section; |
76aec42f | 926 | } |
927 | ||
2f14b1f9 | 928 | /* Return the section to use for string merging. */ |
bb2821c0 | 929 | |
2f14b1f9 | 930 | static section * |
3180a54f | 931 | mergeable_string_section (tree decl ATTRIBUTE_UNUSED, |
932 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED, | |
933 | unsigned int flags ATTRIBUTE_UNUSED) | |
bb2821c0 | 934 | { |
1fc5c8af | 935 | HOST_WIDE_INT len; |
936 | ||
cdb2d692 | 937 | if (HAVE_GAS_SHF_MERGE && flag_merge_constants |
bb2821c0 | 938 | && TREE_CODE (decl) == STRING_CST |
939 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE | |
940 | && align <= 256 | |
1fc5c8af | 941 | && (len = int_size_in_bytes (TREE_TYPE (decl))) > 0 |
942 | && TREE_STRING_LENGTH (decl) >= len) | |
bb2821c0 | 943 | { |
944 | enum machine_mode mode; | |
945 | unsigned int modesize; | |
946 | const char *str; | |
1fc5c8af | 947 | HOST_WIDE_INT i; |
948 | int j, unit; | |
bb2821c0 | 949 | char name[30]; |
950 | ||
951 | mode = TYPE_MODE (TREE_TYPE (TREE_TYPE (decl))); | |
952 | modesize = GET_MODE_BITSIZE (mode); | |
953 | if (modesize >= 8 && modesize <= 256 | |
954 | && (modesize & (modesize - 1)) == 0) | |
955 | { | |
956 | if (align < modesize) | |
957 | align = modesize; | |
958 | ||
959 | str = TREE_STRING_POINTER (decl); | |
bb2821c0 | 960 | unit = GET_MODE_SIZE (mode); |
961 | ||
962 | /* Check for embedded NUL characters. */ | |
963 | for (i = 0; i < len; i += unit) | |
964 | { | |
965 | for (j = 0; j < unit; j++) | |
bc70bd5e | 966 | if (str[i + j] != '\0') |
bb2821c0 | 967 | break; |
968 | if (j == unit) | |
969 | break; | |
970 | } | |
971 | if (i == len - unit) | |
972 | { | |
973 | sprintf (name, ".rodata.str%d.%d", modesize / 8, | |
974 | (int) (align / 8)); | |
975 | flags |= (modesize / 8) | SECTION_MERGE | SECTION_STRINGS; | |
2f14b1f9 | 976 | return get_section (name, flags, NULL); |
bb2821c0 | 977 | } |
978 | } | |
979 | } | |
cdb2d692 | 980 | |
2f14b1f9 | 981 | return readonly_data_section; |
bc70bd5e | 982 | } |
bb2821c0 | 983 | |
2f14b1f9 | 984 | /* Return the section to use for constant merging. */ |
bb2821c0 | 985 | |
2f14b1f9 | 986 | section * |
3180a54f | 987 | mergeable_constant_section (enum machine_mode mode ATTRIBUTE_UNUSED, |
988 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED, | |
989 | unsigned int flags ATTRIBUTE_UNUSED) | |
bb2821c0 | 990 | { |
bb2821c0 | 991 | unsigned int modesize = GET_MODE_BITSIZE (mode); |
992 | ||
cdb2d692 | 993 | if (HAVE_GAS_SHF_MERGE && flag_merge_constants |
bb2821c0 | 994 | && mode != VOIDmode |
995 | && mode != BLKmode | |
996 | && modesize <= align | |
997 | && align >= 8 | |
998 | && align <= 256 | |
999 | && (align & (align - 1)) == 0) | |
1000 | { | |
1001 | char name[24]; | |
1002 | ||
1003 | sprintf (name, ".rodata.cst%d", (int) (align / 8)); | |
1004 | flags |= (align / 8) | SECTION_MERGE; | |
2f14b1f9 | 1005 | return get_section (name, flags, NULL); |
bc70bd5e | 1006 | } |
2f14b1f9 | 1007 | return readonly_data_section; |
bb2821c0 | 1008 | } |
5243fbff | 1009 | \f |
bdf74c8a | 1010 | /* Given NAME, a putative register name, discard any customary prefixes. */ |
1011 | ||
951f0f62 | 1012 | static const char * |
3180a54f | 1013 | strip_reg_name (const char *name) |
bdf74c8a | 1014 | { |
1015 | #ifdef REGISTER_PREFIX | |
1016 | if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX))) | |
1017 | name += strlen (REGISTER_PREFIX); | |
1018 | #endif | |
1019 | if (name[0] == '%' || name[0] == '#') | |
1020 | name++; | |
1021 | return name; | |
1022 | } | |
48c6936b | 1023 | \f |
b2c4af5e | 1024 | /* The user has asked for a DECL to have a particular name. Set (or |
1025 | change) it in such a way that we don't prefix an underscore to | |
1026 | it. */ | |
1027 | void | |
1028 | set_user_assembler_name (tree decl, const char *name) | |
1029 | { | |
45ba1503 | 1030 | char *starred = (char *) alloca (strlen (name) + 2); |
b2c4af5e | 1031 | starred[0] = '*'; |
1032 | strcpy (starred + 1, name); | |
1033 | change_decl_assembler_name (decl, get_identifier (starred)); | |
1034 | SET_DECL_RTL (decl, NULL_RTX); | |
1035 | } | |
1036 | \f | |
5243fbff | 1037 | /* Decode an `asm' spec for a declaration as a register name. |
1038 | Return the register number, or -1 if nothing specified, | |
426b38c9 | 1039 | or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized, |
1040 | or -3 if ASMSPEC is `cc' and is not recognized, | |
1041 | or -4 if ASMSPEC is `memory' and is not recognized. | |
48c6936b | 1042 | Accept an exact spelling or a decimal number. |
1043 | Prefixes such as % are optional. */ | |
5243fbff | 1044 | |
1045 | int | |
3180a54f | 1046 | decode_reg_name (const char *asmspec) |
5243fbff | 1047 | { |
376a0b6e | 1048 | if (asmspec != 0) |
5243fbff | 1049 | { |
1050 | int i; | |
1051 | ||
bdf74c8a | 1052 | /* Get rid of confusing prefixes. */ |
1053 | asmspec = strip_reg_name (asmspec); | |
b7fdac4b | 1054 | |
a6e4a944 | 1055 | /* Allow a decimal number as a "register name". */ |
1056 | for (i = strlen (asmspec) - 1; i >= 0; i--) | |
66a33570 | 1057 | if (! ISDIGIT (asmspec[i])) |
a6e4a944 | 1058 | break; |
1059 | if (asmspec[0] != 0 && i < 0) | |
1060 | { | |
1061 | i = atoi (asmspec); | |
1062 | if (i < FIRST_PSEUDO_REGISTER && i >= 0) | |
1063 | return i; | |
1064 | else | |
1065 | return -2; | |
1066 | } | |
1067 | ||
5243fbff | 1068 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) |
bdf74c8a | 1069 | if (reg_names[i][0] |
1070 | && ! strcmp (asmspec, strip_reg_name (reg_names[i]))) | |
5243fbff | 1071 | return i; |
1072 | ||
5243fbff | 1073 | #ifdef ADDITIONAL_REGISTER_NAMES |
1074 | { | |
0d95286f | 1075 | static const struct { const char *const name; const int number; } table[] |
5243fbff | 1076 | = ADDITIONAL_REGISTER_NAMES; |
1077 | ||
3098b2d3 | 1078 | for (i = 0; i < (int) ARRAY_SIZE (table); i++) |
214e326a | 1079 | if (table[i].name[0] |
1080 | && ! strcmp (asmspec, table[i].name)) | |
5243fbff | 1081 | return table[i].number; |
5243fbff | 1082 | } |
1083 | #endif /* ADDITIONAL_REGISTER_NAMES */ | |
1084 | ||
426b38c9 | 1085 | if (!strcmp (asmspec, "memory")) |
1086 | return -4; | |
1087 | ||
48c6936b | 1088 | if (!strcmp (asmspec, "cc")) |
1089 | return -3; | |
1090 | ||
5243fbff | 1091 | return -2; |
1092 | } | |
1093 | ||
1094 | return -1; | |
1095 | } | |
1096 | \f | |
102e3995 | 1097 | /* Return true if DECL's initializer is suitable for a BSS section. */ |
f2d0e9f1 | 1098 | |
1099 | static bool | |
a9f1838b | 1100 | bss_initializer_p (const_tree decl) |
f2d0e9f1 | 1101 | { |
102e3995 | 1102 | return (DECL_INITIAL (decl) == NULL |
1103 | || DECL_INITIAL (decl) == error_mark_node | |
1104 | || (flag_zero_initialized_in_bss | |
1105 | /* Leave constant zeroes in .rodata so they | |
1106 | can be shared. */ | |
1107 | && !TREE_READONLY (decl) | |
1108 | && initializer_zerop (DECL_INITIAL (decl)))); | |
1109 | } | |
1110 | ||
d5a2a489 | 1111 | /* Compute the alignment of variable specified by DECL. |
1112 | DONT_OUTPUT_DATA is from assemble_variable. */ | |
1113 | ||
e3a1de9d | 1114 | void |
d5a2a489 | 1115 | align_variable (tree decl, bool dont_output_data) |
1116 | { | |
1117 | unsigned int align = DECL_ALIGN (decl); | |
1118 | ||
1119 | /* In the case for initialing an array whose length isn't specified, | |
1120 | where we have not yet been able to do the layout, | |
1121 | figure out the proper alignment now. */ | |
1122 | if (dont_output_data && DECL_SIZE (decl) == 0 | |
1123 | && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) | |
1124 | align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl)))); | |
1125 | ||
1126 | /* Some object file formats have a maximum alignment which they support. | |
1127 | In particular, a.out format supports a maximum alignment of 4. */ | |
1128 | if (align > MAX_OFILE_ALIGNMENT) | |
1129 | { | |
1130 | warning (0, "alignment of %q+D is greater than maximum object " | |
1131 | "file alignment. Using %d", decl, | |
1132 | MAX_OFILE_ALIGNMENT/BITS_PER_UNIT); | |
1133 | align = MAX_OFILE_ALIGNMENT; | |
1134 | } | |
1135 | ||
1136 | /* On some machines, it is good to increase alignment sometimes. */ | |
1137 | if (! DECL_USER_ALIGN (decl)) | |
1138 | { | |
1139 | #ifdef DATA_ALIGNMENT | |
0722e767 | 1140 | unsigned int data_align = DATA_ALIGNMENT (TREE_TYPE (decl), align); |
1141 | /* Don't increase alignment too much for TLS variables - TLS space | |
1142 | is too precious. */ | |
1143 | if (! DECL_THREAD_LOCAL_P (decl) || data_align <= BITS_PER_WORD) | |
1144 | align = data_align; | |
d5a2a489 | 1145 | #endif |
1146 | #ifdef CONSTANT_ALIGNMENT | |
1147 | if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node) | |
0722e767 | 1148 | { |
1149 | unsigned int const_align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), | |
1150 | align); | |
1151 | /* Don't increase alignment too much for TLS variables - TLS space | |
1152 | is too precious. */ | |
1153 | if (! DECL_THREAD_LOCAL_P (decl) || const_align <= BITS_PER_WORD) | |
1154 | align = const_align; | |
1155 | } | |
d5a2a489 | 1156 | #endif |
1157 | } | |
1158 | ||
1159 | /* Reset the alignment in case we have made it tighter, so we can benefit | |
1160 | from it in get_pointer_alignment. */ | |
1161 | DECL_ALIGN (decl) = align; | |
1162 | } | |
1163 | ||
102e3995 | 1164 | /* Return the section into which the given VAR_DECL or CONST_DECL |
1165 | should be placed. PREFER_NOSWITCH_P is true if a noswitch | |
1166 | section should be used wherever possible. */ | |
1167 | ||
1168 | static section * | |
1169 | get_variable_section (tree decl, bool prefer_noswitch_p) | |
1170 | { | |
1171 | int reloc; | |
1172 | ||
1173 | /* If the decl has been given an explicit section name, then it | |
1174 | isn't common, and shouldn't be handled as such. */ | |
1175 | if (DECL_COMMON (decl) && DECL_SECTION_NAME (decl) == NULL) | |
1176 | { | |
1177 | if (DECL_THREAD_LOCAL_P (decl)) | |
1178 | return tls_comm_section; | |
38475469 | 1179 | /* This cannot be common bss for an emulated TLS object without |
1180 | a register_common hook. */ | |
1181 | else if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED | |
1182 | && !targetm.emutls.register_common) | |
1183 | ; | |
1184 | else if (TREE_PUBLIC (decl) && bss_initializer_p (decl)) | |
102e3995 | 1185 | return comm_section; |
1186 | } | |
1187 | ||
1188 | if (DECL_INITIAL (decl) == error_mark_node) | |
1189 | reloc = contains_pointers_p (TREE_TYPE (decl)) ? 3 : 0; | |
1190 | else if (DECL_INITIAL (decl)) | |
1191 | reloc = compute_reloc_for_constant (DECL_INITIAL (decl)); | |
1192 | else | |
1193 | reloc = 0; | |
1194 | ||
1195 | resolve_unique_section (decl, reloc, flag_data_sections); | |
1196 | if (IN_NAMED_SECTION (decl)) | |
1197 | return get_named_section (decl, NULL, reloc); | |
1198 | ||
1199 | if (!DECL_THREAD_LOCAL_P (decl) | |
1200 | && !(prefer_noswitch_p && targetm.have_switchable_bss_sections) | |
1201 | && bss_initializer_p (decl)) | |
1202 | { | |
1203 | if (!TREE_PUBLIC (decl)) | |
1204 | return lcomm_section; | |
1205 | if (bss_noswitch_section) | |
1206 | return bss_noswitch_section; | |
1207 | } | |
1208 | ||
1209 | return targetm.asm_out.select_section (decl, reloc, DECL_ALIGN (decl)); | |
1210 | } | |
1211 | ||
1212 | /* Return the block into which object_block DECL should be placed. */ | |
1213 | ||
1214 | static struct object_block * | |
1215 | get_block_for_decl (tree decl) | |
1216 | { | |
1217 | section *sect; | |
f2d0e9f1 | 1218 | |
1219 | if (TREE_CODE (decl) == VAR_DECL) | |
1220 | { | |
1221 | /* The object must be defined in this translation unit. */ | |
1222 | if (DECL_EXTERNAL (decl)) | |
102e3995 | 1223 | return NULL; |
f2d0e9f1 | 1224 | |
1225 | /* There's no point using object blocks for something that is | |
1226 | isolated by definition. */ | |
1227 | if (DECL_ONE_ONLY (decl)) | |
102e3995 | 1228 | return NULL; |
f2d0e9f1 | 1229 | } |
1230 | ||
1231 | /* We can only calculate block offsets if the decl has a known | |
1232 | constant size. */ | |
1233 | if (DECL_SIZE_UNIT (decl) == NULL) | |
102e3995 | 1234 | return NULL; |
f2d0e9f1 | 1235 | if (!host_integerp (DECL_SIZE_UNIT (decl), 1)) |
102e3995 | 1236 | return NULL; |
f2d0e9f1 | 1237 | |
102e3995 | 1238 | /* Find out which section should contain DECL. We cannot put it into |
1239 | an object block if it requires a standalone definition. */ | |
d5a2a489 | 1240 | if (TREE_CODE (decl) == VAR_DECL) |
1241 | align_variable (decl, 0); | |
102e3995 | 1242 | sect = get_variable_section (decl, true); |
1243 | if (SECTION_STYLE (sect) == SECTION_NOSWITCH) | |
1244 | return NULL; | |
f2d0e9f1 | 1245 | |
102e3995 | 1246 | return get_block_for_section (sect); |
f2d0e9f1 | 1247 | } |
1248 | ||
102e3995 | 1249 | /* Make sure block symbol SYMBOL is in block BLOCK. */ |
f2d0e9f1 | 1250 | |
1251 | static void | |
102e3995 | 1252 | change_symbol_block (rtx symbol, struct object_block *block) |
f2d0e9f1 | 1253 | { |
102e3995 | 1254 | if (block != SYMBOL_REF_BLOCK (symbol)) |
f2d0e9f1 | 1255 | { |
1256 | gcc_assert (SYMBOL_REF_BLOCK_OFFSET (symbol) < 0); | |
102e3995 | 1257 | SYMBOL_REF_BLOCK (symbol) = block; |
f2d0e9f1 | 1258 | } |
1259 | } | |
1260 | ||
102e3995 | 1261 | /* Return true if it is possible to put DECL in an object_block. */ |
f2d0e9f1 | 1262 | |
102e3995 | 1263 | static bool |
1264 | use_blocks_for_decl_p (tree decl) | |
f2d0e9f1 | 1265 | { |
102e3995 | 1266 | /* Only data DECLs can be placed into object blocks. */ |
1267 | if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != CONST_DECL) | |
1268 | return false; | |
f2d0e9f1 | 1269 | |
102e3995 | 1270 | /* Detect decls created by dw2_force_const_mem. Such decls are |
1271 | special because DECL_INITIAL doesn't specify the decl's true value. | |
1272 | dw2_output_indirect_constants will instead call assemble_variable | |
1273 | with dont_output_data set to 1 and then print the contents itself. */ | |
1274 | if (DECL_INITIAL (decl) == decl) | |
1275 | return false; | |
f2d0e9f1 | 1276 | |
53861d5d | 1277 | /* If this decl is an alias, then we don't want to emit a definition. */ |
1278 | if (lookup_attribute ("alias", DECL_ATTRIBUTES (decl))) | |
1279 | return false; | |
1280 | ||
102e3995 | 1281 | return true; |
f2d0e9f1 | 1282 | } |
1283 | ||
0e8e37b2 | 1284 | /* Create the DECL_RTL for a VAR_DECL or FUNCTION_DECL. DECL should |
1285 | have static storage duration. In other words, it should not be an | |
1286 | automatic variable, including PARM_DECLs. | |
1287 | ||
1288 | There is, however, one exception: this function handles variables | |
1289 | explicitly placed in a particular register by the user. | |
1290 | ||
5243fbff | 1291 | This is never called for PARM_DECL nodes. */ |
1292 | ||
1293 | void | |
b2c4af5e | 1294 | make_decl_rtl (tree decl) |
5243fbff | 1295 | { |
71d9fc9b | 1296 | const char *name = 0; |
649d8da6 | 1297 | int reg_number; |
d05cd611 | 1298 | rtx x; |
649d8da6 | 1299 | |
0e8e37b2 | 1300 | /* Check that we are not being given an automatic variable. */ |
22167fd5 | 1301 | gcc_assert (TREE_CODE (decl) != PARM_DECL |
1302 | && TREE_CODE (decl) != RESULT_DECL); | |
1303 | ||
274a89f2 | 1304 | /* A weak alias has TREE_PUBLIC set but not the other bits. */ |
22167fd5 | 1305 | gcc_assert (TREE_CODE (decl) != VAR_DECL |
1306 | || TREE_STATIC (decl) | |
1307 | || TREE_PUBLIC (decl) | |
1308 | || DECL_EXTERNAL (decl) | |
1309 | || DECL_REGISTER (decl)); | |
b215c058 | 1310 | |
0e8e37b2 | 1311 | /* And that we were not given a type or a label. */ |
22167fd5 | 1312 | gcc_assert (TREE_CODE (decl) != TYPE_DECL |
1313 | && TREE_CODE (decl) != LABEL_DECL); | |
0e8e37b2 | 1314 | |
71d9fc9b | 1315 | /* For a duplicate declaration, we can be called twice on the |
1316 | same DECL node. Don't discard the RTL already made. */ | |
0e8e37b2 | 1317 | if (DECL_RTL_SET_P (decl)) |
5243fbff | 1318 | { |
71d9fc9b | 1319 | /* If the old RTL had the wrong mode, fix the mode. */ |
f2d0e9f1 | 1320 | x = DECL_RTL (decl); |
1321 | if (GET_MODE (x) != DECL_MODE (decl)) | |
1322 | SET_DECL_RTL (decl, adjust_address_nv (x, DECL_MODE (decl), 0)); | |
2c8daaf1 | 1323 | |
b2c4af5e | 1324 | if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)) |
1325 | return; | |
1326 | ||
8bc122e1 | 1327 | /* ??? Another way to do this would be to maintain a hashed |
1328 | table of such critters. Instead of adding stuff to a DECL | |
1329 | to give certain attributes to it, we could use an external | |
1330 | hash map from DECL to set of attributes. */ | |
1331 | ||
71d9fc9b | 1332 | /* Let the target reassign the RTL if it wants. |
1333 | This is necessary, for example, when one machine specific | |
1334 | decl attribute overrides another. */ | |
6fb33aa0 | 1335 | targetm.encode_section_info (decl, DECL_RTL (decl), false); |
4ee9c684 | 1336 | |
6617cbc1 | 1337 | /* If the symbol has a SYMBOL_REF_BLOCK field, update it based |
1338 | on the new decl information. */ | |
f2d0e9f1 | 1339 | if (MEM_P (x) |
1340 | && GET_CODE (XEXP (x, 0)) == SYMBOL_REF | |
6617cbc1 | 1341 | && SYMBOL_REF_HAS_BLOCK_INFO_P (XEXP (x, 0))) |
102e3995 | 1342 | change_symbol_block (XEXP (x, 0), get_block_for_decl (decl)); |
f2d0e9f1 | 1343 | |
4ee9c684 | 1344 | /* Make this function static known to the mudflap runtime. */ |
1345 | if (flag_mudflap && TREE_CODE (decl) == VAR_DECL) | |
1346 | mudflap_enqueue_decl (decl); | |
1347 | ||
71d9fc9b | 1348 | return; |
5243fbff | 1349 | } |
1350 | ||
a6df3a0e | 1351 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
b215c058 | 1352 | |
287cbb2e | 1353 | if (name[0] != '*' && TREE_CODE (decl) != FUNCTION_DECL |
1354 | && DECL_REGISTER (decl)) | |
1355 | { | |
b215c058 | 1356 | error ("register name not specified for %q+D", decl); |
287cbb2e | 1357 | } |
1358 | else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)) | |
5243fbff | 1359 | { |
287cbb2e | 1360 | const char *asmspec = name+1; |
1361 | reg_number = decode_reg_name (asmspec); | |
5243fbff | 1362 | /* First detect errors in declaring global registers. */ |
71d9fc9b | 1363 | if (reg_number == -1) |
3cf8b391 | 1364 | error ("register name not specified for %q+D", decl); |
71d9fc9b | 1365 | else if (reg_number < 0) |
3cf8b391 | 1366 | error ("invalid register name for %q+D", decl); |
71d9fc9b | 1367 | else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode) |
3cf8b391 | 1368 | error ("data type of %q+D isn%'t suitable for a register", |
1369 | decl); | |
71d9fc9b | 1370 | else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl)))) |
3cf8b391 | 1371 | error ("register specified for %q+D isn%'t suitable for data type", |
1372 | decl); | |
5243fbff | 1373 | /* Now handle properly declared static register variables. */ |
71d9fc9b | 1374 | else |
5243fbff | 1375 | { |
1376 | int nregs; | |
b4cc3359 | 1377 | |
07a60acd | 1378 | if (DECL_INITIAL (decl) != 0 && TREE_STATIC (decl)) |
5243fbff | 1379 | { |
1380 | DECL_INITIAL (decl) = 0; | |
1381 | error ("global register variable has initial value"); | |
1382 | } | |
5243fbff | 1383 | if (TREE_THIS_VOLATILE (decl)) |
bf2a1b05 | 1384 | warning (OPT_Wvolatile_register_var, |
1385 | "optimization may eliminate reads and/or " | |
1386 | "writes to register variables"); | |
a1cd5e50 | 1387 | |
1388 | /* If the user specified one of the eliminables registers here, | |
1389 | e.g., FRAME_POINTER_REGNUM, we don't want to get this variable | |
a68730c1 | 1390 | confused with that register and be eliminated. This usage is |
1391 | somewhat suspect... */ | |
1392 | ||
1393 | SET_DECL_RTL (decl, gen_rtx_raw_REG (DECL_MODE (decl), reg_number)); | |
1394 | ORIGINAL_REGNO (DECL_RTL (decl)) = reg_number; | |
5243fbff | 1395 | REG_USERVAR_P (DECL_RTL (decl)) = 1; |
1396 | ||
125c7a9d | 1397 | if (TREE_STATIC (decl)) |
5243fbff | 1398 | { |
c312ec05 | 1399 | /* Make this register global, so not usable for anything |
1400 | else. */ | |
d300bd48 | 1401 | #ifdef ASM_DECLARE_REGISTER_GLOBAL |
91bf0af7 | 1402 | name = IDENTIFIER_POINTER (DECL_NAME (decl)); |
d300bd48 | 1403 | ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name); |
1404 | #endif | |
67d6c12b | 1405 | nregs = hard_regno_nregs[reg_number][DECL_MODE (decl)]; |
5243fbff | 1406 | while (nregs > 0) |
c312ec05 | 1407 | globalize_reg (reg_number + --nregs); |
5243fbff | 1408 | } |
5243fbff | 1409 | |
71d9fc9b | 1410 | /* As a register variable, it has no section. */ |
1411 | return; | |
1412 | } | |
1413 | } | |
71d9fc9b | 1414 | /* Now handle ordinary static variables and functions (in memory). |
1415 | Also handle vars declared register invalidly. */ | |
376a0b6e | 1416 | else if (name[0] == '*') |
1417 | { | |
1418 | #ifdef REGISTER_PREFIX | |
1419 | if (strlen (REGISTER_PREFIX) != 0) | |
1420 | { | |
b00e10ba | 1421 | reg_number = decode_reg_name (name); |
376a0b6e | 1422 | if (reg_number >= 0 || reg_number == -3) |
3cf8b391 | 1423 | error ("register name given for non-register variable %q+D", decl); |
376a0b6e | 1424 | } |
1425 | #endif | |
1426 | } | |
71d9fc9b | 1427 | |
1428 | /* Specifying a section attribute on a variable forces it into a | |
1be87b72 | 1429 | non-.bss section, and thus it cannot be common. */ |
71d9fc9b | 1430 | if (TREE_CODE (decl) == VAR_DECL |
1431 | && DECL_SECTION_NAME (decl) != NULL_TREE | |
1432 | && DECL_INITIAL (decl) == NULL_TREE | |
1433 | && DECL_COMMON (decl)) | |
1434 | DECL_COMMON (decl) = 0; | |
1435 | ||
15bccea9 | 1436 | /* Variables can't be both common and weak. */ |
1437 | if (TREE_CODE (decl) == VAR_DECL && DECL_WEAK (decl)) | |
1438 | DECL_COMMON (decl) = 0; | |
1439 | ||
f2d0e9f1 | 1440 | if (use_object_blocks_p () && use_blocks_for_decl_p (decl)) |
102e3995 | 1441 | x = create_block_symbol (name, get_block_for_decl (decl), -1); |
f2d0e9f1 | 1442 | else |
1443 | x = gen_rtx_SYMBOL_REF (Pmode, name); | |
001be062 | 1444 | SYMBOL_REF_WEAK (x) = DECL_WEAK (decl); |
b864739b | 1445 | SET_SYMBOL_REF_DECL (x, decl); |
3180a54f | 1446 | |
001be062 | 1447 | x = gen_rtx_MEM (DECL_MODE (decl), x); |
71d9fc9b | 1448 | if (TREE_CODE (decl) != FUNCTION_DECL) |
d05cd611 | 1449 | set_mem_attributes (x, decl, 1); |
1450 | SET_DECL_RTL (decl, x); | |
71d9fc9b | 1451 | |
1452 | /* Optionally set flags or add text to the name to record information | |
1453 | such as that it is a function name. | |
1454 | If the name is changed, the macro ASM_OUTPUT_LABELREF | |
1455 | will have to know how to strip this information. */ | |
6fb33aa0 | 1456 | targetm.encode_section_info (decl, DECL_RTL (decl), true); |
4ee9c684 | 1457 | |
1458 | /* Make this function static known to the mudflap runtime. */ | |
1459 | if (flag_mudflap && TREE_CODE (decl) == VAR_DECL) | |
1460 | mudflap_enqueue_decl (decl); | |
5243fbff | 1461 | } |
1462 | \f | |
1463 | /* Output a string of literal assembler code | |
1464 | for an `asm' keyword used between functions. */ | |
1465 | ||
1466 | void | |
3180a54f | 1467 | assemble_asm (tree string) |
5243fbff | 1468 | { |
1469 | app_enable (); | |
1470 | ||
1471 | if (TREE_CODE (string) == ADDR_EXPR) | |
1472 | string = TREE_OPERAND (string, 0); | |
1473 | ||
1474 | fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string)); | |
1475 | } | |
1476 | ||
01d15dc5 | 1477 | /* Record an element in the table of global destructors. SYMBOL is |
1478 | a SYMBOL_REF of the function to be called; PRIORITY is a number | |
1479 | between 0 and MAX_INIT_PRIORITY. */ | |
5243fbff | 1480 | |
1481 | void | |
770698a1 | 1482 | default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED, |
1483 | int priority ATTRIBUTE_UNUSED) | |
5243fbff | 1484 | { |
d0de818d | 1485 | #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO |
01d15dc5 | 1486 | /* Tell GNU LD that this is part of the static destructor set. |
1487 | This will work for any system that uses stabs, most usefully | |
1488 | aout systems. */ | |
d0de818d | 1489 | dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */); |
1490 | dbxout_stab_value_label (XSTR (symbol, 0)); | |
1491 | #else | |
1492 | sorry ("global destructors not supported on this target"); | |
1493 | #endif | |
01d15dc5 | 1494 | } |
14cd71fe | 1495 | |
6c181a06 | 1496 | /* Write the address of the entity given by SYMBOL to SEC. */ |
1497 | void | |
1498 | assemble_addr_to_section (rtx symbol, section *sec) | |
1499 | { | |
1500 | switch_to_section (sec); | |
1501 | assemble_align (POINTER_SIZE); | |
1502 | assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1); | |
1503 | } | |
1504 | ||
1505 | /* Return the numbered .ctors.N (if CONSTRUCTOR_P) or .dtors.N (if | |
1506 | not) section for PRIORITY. */ | |
1507 | section * | |
1508 | get_cdtor_priority_section (int priority, bool constructor_p) | |
01d15dc5 | 1509 | { |
01d15dc5 | 1510 | char buf[16]; |
14cd71fe | 1511 | |
1e625a2e | 1512 | /* ??? This only works reliably with the GNU linker. */ |
6c181a06 | 1513 | sprintf (buf, "%s.%.5u", |
1514 | constructor_p ? ".ctors" : ".dtors", | |
1515 | /* Invert the numbering so the linker puts us in the proper | |
1516 | order; constructors are run from right to left, and the | |
1517 | linker sorts in increasing order. */ | |
1518 | MAX_INIT_PRIORITY - priority); | |
1519 | return get_section (buf, SECTION_WRITE, NULL); | |
1520 | } | |
1521 | ||
1522 | void | |
1523 | default_named_section_asm_out_destructor (rtx symbol, int priority) | |
1524 | { | |
1525 | section *sec; | |
1526 | ||
01d15dc5 | 1527 | if (priority != DEFAULT_INIT_PRIORITY) |
6c181a06 | 1528 | sec = get_cdtor_priority_section (priority, |
1529 | /*constructor_p=*/false); | |
1530 | else | |
1531 | sec = get_section (".dtors", SECTION_WRITE, NULL); | |
14cd71fe | 1532 | |
6c181a06 | 1533 | assemble_addr_to_section (symbol, sec); |
01d15dc5 | 1534 | } |
1535 | ||
1536 | #ifdef DTORS_SECTION_ASM_OP | |
01d15dc5 | 1537 | void |
3180a54f | 1538 | default_dtor_section_asm_out_destructor (rtx symbol, |
1539 | int priority ATTRIBUTE_UNUSED) | |
01d15dc5 | 1540 | { |
6c181a06 | 1541 | assemble_addr_to_section (symbol, dtors_section); |
01d15dc5 | 1542 | } |
1543 | #endif | |
1544 | ||
5243fbff | 1545 | /* Likewise for global constructors. */ |
1546 | ||
1547 | void | |
770698a1 | 1548 | default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED, |
1549 | int priority ATTRIBUTE_UNUSED) | |
5243fbff | 1550 | { |
d0de818d | 1551 | #if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO |
01d15dc5 | 1552 | /* Tell GNU LD that this is part of the static destructor set. |
1553 | This will work for any system that uses stabs, most usefully | |
1554 | aout systems. */ | |
d0de818d | 1555 | dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */); |
1556 | dbxout_stab_value_label (XSTR (symbol, 0)); | |
1557 | #else | |
1558 | sorry ("global constructors not supported on this target"); | |
1559 | #endif | |
01d15dc5 | 1560 | } |
14cd71fe | 1561 | |
01d15dc5 | 1562 | void |
3180a54f | 1563 | default_named_section_asm_out_constructor (rtx symbol, int priority) |
01d15dc5 | 1564 | { |
6c181a06 | 1565 | section *sec; |
14cd71fe | 1566 | |
01d15dc5 | 1567 | if (priority != DEFAULT_INIT_PRIORITY) |
6c181a06 | 1568 | sec = get_cdtor_priority_section (priority, |
1569 | /*constructor_p=*/true); | |
1570 | else | |
1571 | sec = get_section (".ctors", SECTION_WRITE, NULL); | |
14cd71fe | 1572 | |
6c181a06 | 1573 | assemble_addr_to_section (symbol, sec); |
01d15dc5 | 1574 | } |
1575 | ||
1576 | #ifdef CTORS_SECTION_ASM_OP | |
01d15dc5 | 1577 | void |
3180a54f | 1578 | default_ctor_section_asm_out_constructor (rtx symbol, |
1579 | int priority ATTRIBUTE_UNUSED) | |
01d15dc5 | 1580 | { |
6c181a06 | 1581 | assemble_addr_to_section (symbol, ctors_section); |
01d15dc5 | 1582 | } |
1583 | #endif | |
5243fbff | 1584 | \f |
71564039 | 1585 | /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with |
f712a0dc | 1586 | a nonzero value if the constant pool should be output before the |
71564039 | 1587 | start of the function, or a zero value if the pool should output |
1588 | after the end of the function. The default is to put it before the | |
1589 | start. */ | |
1590 | ||
1591 | #ifndef CONSTANT_POOL_BEFORE_FUNCTION | |
1592 | #define CONSTANT_POOL_BEFORE_FUNCTION 1 | |
1593 | #endif | |
1594 | ||
3cad5dd7 | 1595 | /* DECL is an object (either VAR_DECL or FUNCTION_DECL) which is going |
1596 | to be output to assembler. | |
1597 | Set first_global_object_name and weak_global_object_name as appropriate. */ | |
1598 | ||
1599 | void | |
1600 | notice_global_symbol (tree decl) | |
1601 | { | |
362883d3 | 1602 | const char **type = &first_global_object_name; |
1603 | ||
1604 | if (first_global_object_name | |
7392c0b4 | 1605 | || !TREE_PUBLIC (decl) |
1606 | || DECL_EXTERNAL (decl) | |
362883d3 | 1607 | || !DECL_NAME (decl) |
1608 | || (TREE_CODE (decl) != FUNCTION_DECL | |
1609 | && (TREE_CODE (decl) != VAR_DECL | |
1610 | || (DECL_COMMON (decl) | |
1611 | && (DECL_INITIAL (decl) == 0 | |
21108847 | 1612 | || DECL_INITIAL (decl) == error_mark_node)))) |
e16ceb8e | 1613 | || !MEM_P (DECL_RTL (decl))) |
362883d3 | 1614 | return; |
1615 | ||
8e43612b | 1616 | /* We win when global object is found, but it is useful to know about weak |
362883d3 | 1617 | symbol as well so we can produce nicer unique names. */ |
a6af46b6 | 1618 | if (DECL_WEAK (decl) || DECL_ONE_ONLY (decl) || flag_shlib) |
362883d3 | 1619 | type = &weak_global_object_name; |
1620 | ||
1621 | if (!*type) | |
3cad5dd7 | 1622 | { |
1623 | const char *p; | |
724ea712 | 1624 | const char *name; |
3cad5dd7 | 1625 | rtx decl_rtl = DECL_RTL (decl); |
1626 | ||
6fb33aa0 | 1627 | p = targetm.strip_name_encoding (XSTR (XEXP (decl_rtl, 0), 0)); |
724ea712 | 1628 | name = ggc_strdup (p); |
3cad5dd7 | 1629 | |
362883d3 | 1630 | *type = name; |
3cad5dd7 | 1631 | } |
1632 | } | |
1633 | ||
5243fbff | 1634 | /* Output assembler code for the constant pool of a function and associated |
1635 | with defining the name of the function. DECL describes the function. | |
1636 | NAME is the function's name. For the constant pool, we use the current | |
1637 | constant pool data. */ | |
1638 | ||
1639 | void | |
3180a54f | 1640 | assemble_start_function (tree decl, const char *fnname) |
5243fbff | 1641 | { |
1642 | int align; | |
4d0e931f | 1643 | char tmp_label[100]; |
1897b881 | 1644 | bool hot_label_written = false; |
5243fbff | 1645 | |
abe32cce | 1646 | crtl->subsections.unlikely_text_section_name = NULL; |
b215c058 | 1647 | |
1897b881 | 1648 | first_function_block_is_cold = false; |
4d0e931f | 1649 | if (flag_reorder_blocks_and_partition) |
1650 | { | |
48eb5ed6 | 1651 | ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTB", const_labelno); |
abe32cce | 1652 | crtl->subsections.hot_section_label = ggc_strdup (tmp_label); |
48eb5ed6 | 1653 | ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDB", const_labelno); |
abe32cce | 1654 | crtl->subsections.cold_section_label = ggc_strdup (tmp_label); |
48eb5ed6 | 1655 | ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LHOTE", const_labelno); |
abe32cce | 1656 | crtl->subsections.hot_section_end_label = ggc_strdup (tmp_label); |
48eb5ed6 | 1657 | ASM_GENERATE_INTERNAL_LABEL (tmp_label, "LCOLDE", const_labelno); |
abe32cce | 1658 | crtl->subsections.cold_section_end_label = ggc_strdup (tmp_label); |
4d0e931f | 1659 | const_labelno++; |
1660 | } | |
1661 | else | |
1662 | { | |
abe32cce | 1663 | crtl->subsections.hot_section_label = NULL; |
1664 | crtl->subsections.cold_section_label = NULL; | |
1665 | crtl->subsections.hot_section_end_label = NULL; | |
1666 | crtl->subsections.cold_section_end_label = NULL; | |
4d0e931f | 1667 | } |
1897b881 | 1668 | |
5243fbff | 1669 | /* The following code does not need preprocessing in the assembler. */ |
1670 | ||
1671 | app_disable (); | |
1672 | ||
71564039 | 1673 | if (CONSTANT_POOL_BEFORE_FUNCTION) |
372df111 | 1674 | output_constant_pool (fnname, decl); |
5243fbff | 1675 | |
792a073a | 1676 | resolve_unique_section (decl, 0, flag_function_sections); |
1677 | ||
1897b881 | 1678 | /* Make sure the not and cold text (code) sections are properly |
1679 | aligned. This is necessary here in the case where the function | |
1680 | has both hot and cold sections, because we don't want to re-set | |
1681 | the alignment when the section switch happens mid-function. */ | |
480c55ab | 1682 | |
1683 | if (flag_reorder_blocks_and_partition) | |
1684 | { | |
5fbee89d | 1685 | switch_to_section (unlikely_text_section ()); |
6c96b31e | 1686 | assemble_align (DECL_ALIGN (decl)); |
abe32cce | 1687 | ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_label); |
186849ba | 1688 | |
1689 | /* When the function starts with a cold section, we need to explicitly | |
1690 | align the hot section and write out the hot section label. | |
1691 | But if the current function is a thunk, we do not have a CFG. */ | |
9247818a | 1692 | if (!cfun->is_thunk |
186849ba | 1693 | && BB_PARTITION (ENTRY_BLOCK_PTR->next_bb) == BB_COLD_PARTITION) |
1897b881 | 1694 | { |
2f14b1f9 | 1695 | switch_to_section (text_section); |
6c96b31e | 1696 | assemble_align (DECL_ALIGN (decl)); |
abe32cce | 1697 | ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label); |
1897b881 | 1698 | hot_label_written = true; |
1699 | first_function_block_is_cold = true; | |
1700 | } | |
1701 | } | |
1702 | else if (DECL_SECTION_NAME (decl)) | |
1703 | { | |
1704 | /* Calls to function_section rely on first_function_block_is_cold | |
1705 | being accurate. The first block may be cold even if we aren't | |
1706 | doing partitioning, if the entire function was decided by | |
1707 | choose_function_section (predict.c) to be cold. */ | |
1708 | ||
1897b881 | 1709 | initialize_cold_section_name (); |
1710 | ||
abe32cce | 1711 | if (crtl->subsections.unlikely_text_section_name |
b90d852a | 1712 | && strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)), |
abe32cce | 1713 | crtl->subsections.unlikely_text_section_name) == 0) |
1897b881 | 1714 | first_function_block_is_cold = true; |
480c55ab | 1715 | } |
1716 | ||
5fbee89d | 1717 | in_cold_section_p = first_function_block_is_cold; |
1897b881 | 1718 | |
1719 | /* Switch to the correct text section for the start of the function. */ | |
1720 | ||
2f14b1f9 | 1721 | switch_to_section (function_section (decl)); |
b215c058 | 1722 | if (flag_reorder_blocks_and_partition |
85d31d70 | 1723 | && !hot_label_written) |
abe32cce | 1724 | ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_label); |
5243fbff | 1725 | |
1726 | /* Tell assembler to move to target machine's alignment for functions. */ | |
097b5c8b | 1727 | align = floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT); |
5243fbff | 1728 | if (align > 0) |
77ec0c64 | 1729 | { |
1730 | ASM_OUTPUT_ALIGN (asm_out_file, align); | |
1731 | } | |
5243fbff | 1732 | |
61e95947 | 1733 | /* Handle a user-specified function alignment. |
097b5c8b | 1734 | Note that we still need to align to DECL_ALIGN, as above, |
61e95947 | 1735 | because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */ |
097b5c8b | 1736 | if (! DECL_USER_ALIGN (decl) |
1737 | && align_functions_log > align | |
7baffbd3 | 1738 | && optimize_function_for_speed_p (cfun)) |
61e95947 | 1739 | { |
1740 | #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN | |
b7fdac4b | 1741 | ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file, |
bc70bd5e | 1742 | align_functions_log, align_functions - 1); |
61e95947 | 1743 | #else |
1744 | ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log); | |
1745 | #endif | |
1746 | } | |
1747 | ||
5243fbff | 1748 | #ifdef ASM_OUTPUT_FUNCTION_PREFIX |
1749 | ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname); | |
1750 | #endif | |
1751 | ||
f76df888 | 1752 | (*debug_hooks->begin_function) (decl); |
5243fbff | 1753 | |
1754 | /* Make function name accessible from other files, if appropriate. */ | |
1755 | ||
1756 | if (TREE_PUBLIC (decl)) | |
1757 | { | |
3cad5dd7 | 1758 | notice_global_symbol (decl); |
b67f8fe7 | 1759 | |
1fbd58a2 | 1760 | globalize_decl (decl); |
01694f08 | 1761 | |
1762 | maybe_assemble_visibility (decl); | |
5243fbff | 1763 | } |
1764 | ||
9423c9b7 | 1765 | if (DECL_PRESERVE_P (decl)) |
1766 | targetm.asm_out.mark_decl_preserved (fnname); | |
1767 | ||
8b332087 | 1768 | /* Do any machine/system dependent processing of the function name. */ |
47f532a0 | 1769 | #ifdef ASM_DECLARE_FUNCTION_NAME |
b54842d8 | 1770 | ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl); |
47f532a0 | 1771 | #else |
b54842d8 | 1772 | /* Standard thing is just output label for the function. */ |
1773 | ASM_OUTPUT_LABEL (asm_out_file, fnname); | |
5243fbff | 1774 | #endif /* ASM_DECLARE_FUNCTION_NAME */ |
1775 | } | |
1776 | ||
1777 | /* Output assembler code associated with defining the size of the | |
1778 | function. DECL describes the function. NAME is the function's name. */ | |
1779 | ||
1780 | void | |
c61867e3 | 1781 | assemble_end_function (tree decl, const char *fnname ATTRIBUTE_UNUSED) |
5243fbff | 1782 | { |
1783 | #ifdef ASM_DECLARE_FUNCTION_SIZE | |
3eb32482 | 1784 | /* We could have switched section in the middle of the function. */ |
1785 | if (flag_reorder_blocks_and_partition) | |
2f14b1f9 | 1786 | switch_to_section (function_section (decl)); |
5243fbff | 1787 | ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl); |
1788 | #endif | |
71564039 | 1789 | if (! CONSTANT_POOL_BEFORE_FUNCTION) |
e96a60f8 | 1790 | { |
372df111 | 1791 | output_constant_pool (fnname, decl); |
2f14b1f9 | 1792 | switch_to_section (function_section (decl)); /* need to switch back */ |
e96a60f8 | 1793 | } |
1897b881 | 1794 | /* Output labels for end of hot/cold text sections (to be used by |
1795 | debug info.) */ | |
85d31d70 | 1796 | if (flag_reorder_blocks_and_partition) |
1797 | { | |
2f14b1f9 | 1798 | section *save_text_section; |
4d0e931f | 1799 | |
85d31d70 | 1800 | save_text_section = in_section; |
5fbee89d | 1801 | switch_to_section (unlikely_text_section ()); |
abe32cce | 1802 | ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.cold_section_end_label); |
792a073a | 1803 | if (first_function_block_is_cold) |
2f14b1f9 | 1804 | switch_to_section (text_section); |
792a073a | 1805 | else |
2f14b1f9 | 1806 | switch_to_section (function_section (decl)); |
abe32cce | 1807 | ASM_OUTPUT_LABEL (asm_out_file, crtl->subsections.hot_section_end_label); |
2f14b1f9 | 1808 | switch_to_section (save_text_section); |
85d31d70 | 1809 | } |
5243fbff | 1810 | } |
1811 | \f | |
1812 | /* Assemble code to leave SIZE bytes of zeros. */ | |
1813 | ||
1814 | void | |
3180a54f | 1815 | assemble_zeros (unsigned HOST_WIDE_INT size) |
5243fbff | 1816 | { |
482465ac | 1817 | /* Do no output if -fsyntax-only. */ |
1818 | if (flag_syntax_only) | |
1819 | return; | |
1820 | ||
5243fbff | 1821 | #ifdef ASM_NO_SKIP_IN_TEXT |
1822 | /* The `space' pseudo in the text section outputs nop insns rather than 0s, | |
1823 | so we must output 0s explicitly in the text section. */ | |
2f14b1f9 | 1824 | if (ASM_NO_SKIP_IN_TEXT && (in_section->common.flags & SECTION_CODE) != 0) |
5243fbff | 1825 | { |
d716c068 | 1826 | unsigned HOST_WIDE_INT i; |
09d688ff | 1827 | for (i = 0; i < size; i++) |
1828 | assemble_integer (const0_rtx, 1, BITS_PER_UNIT, 1); | |
5243fbff | 1829 | } |
1830 | else | |
1831 | #endif | |
fef5c36c | 1832 | if (size > 0) |
b54842d8 | 1833 | ASM_OUTPUT_SKIP (asm_out_file, size); |
5243fbff | 1834 | } |
1835 | ||
b4cf14c6 | 1836 | /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */ |
1837 | ||
1838 | void | |
3180a54f | 1839 | assemble_align (int align) |
b4cf14c6 | 1840 | { |
1841 | if (align > BITS_PER_UNIT) | |
77ec0c64 | 1842 | { |
1843 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
1844 | } | |
b4cf14c6 | 1845 | } |
1846 | ||
5243fbff | 1847 | /* Assemble a string constant with the specified C string as contents. */ |
1848 | ||
1849 | void | |
3180a54f | 1850 | assemble_string (const char *p, int size) |
5243fbff | 1851 | { |
5243fbff | 1852 | int pos = 0; |
1853 | int maximum = 2000; | |
1854 | ||
1855 | /* If the string is very long, split it up. */ | |
1856 | ||
1857 | while (pos < size) | |
1858 | { | |
1859 | int thissize = size - pos; | |
1860 | if (thissize > maximum) | |
1861 | thissize = maximum; | |
1862 | ||
b54842d8 | 1863 | ASM_OUTPUT_ASCII (asm_out_file, p, thissize); |
5243fbff | 1864 | |
1865 | pos += thissize; | |
1866 | p += thissize; | |
1867 | } | |
1868 | } | |
60a92092 | 1869 | |
5243fbff | 1870 | \f |
102e3995 | 1871 | /* A noswitch_section_callback for lcomm_section. */ |
1872 | ||
1873 | static bool | |
1874 | emit_local (tree decl ATTRIBUTE_UNUSED, | |
1875 | const char *name ATTRIBUTE_UNUSED, | |
1876 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
1877 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED) | |
1878 | { | |
1879 | #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL | |
1880 | ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, | |
1881 | size, DECL_ALIGN (decl)); | |
1882 | return true; | |
1883 | #elif defined ASM_OUTPUT_ALIGNED_LOCAL | |
1884 | ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl)); | |
1885 | return true; | |
f937cbd7 | 1886 | #else |
102e3995 | 1887 | ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded); |
1888 | return false; | |
f937cbd7 | 1889 | #endif |
102e3995 | 1890 | } |
f937cbd7 | 1891 | |
102e3995 | 1892 | /* A noswitch_section_callback for bss_noswitch_section. */ |
1893 | ||
1894 | #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS | |
1895 | static bool | |
1896 | emit_bss (tree decl ATTRIBUTE_UNUSED, | |
1897 | const char *name ATTRIBUTE_UNUSED, | |
1898 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
1899 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED) | |
1900 | { | |
f937cbd7 | 1901 | #if defined ASM_OUTPUT_ALIGNED_BSS |
102e3995 | 1902 | ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl)); |
1903 | return true; | |
f937cbd7 | 1904 | #else |
102e3995 | 1905 | ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded); |
1906 | return false; | |
f937cbd7 | 1907 | #endif |
102e3995 | 1908 | } |
f937cbd7 | 1909 | #endif |
1910 | ||
102e3995 | 1911 | /* A noswitch_section_callback for comm_section. */ |
1912 | ||
1913 | static bool | |
1914 | emit_common (tree decl ATTRIBUTE_UNUSED, | |
1915 | const char *name ATTRIBUTE_UNUSED, | |
1916 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
1917 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED) | |
1918 | { | |
f937cbd7 | 1919 | #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON |
102e3995 | 1920 | ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, |
1921 | size, DECL_ALIGN (decl)); | |
1922 | return true; | |
1923 | #elif defined ASM_OUTPUT_ALIGNED_COMMON | |
1924 | ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl)); | |
1925 | return true; | |
f937cbd7 | 1926 | #else |
102e3995 | 1927 | ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded); |
1928 | return false; | |
f937cbd7 | 1929 | #endif |
102e3995 | 1930 | } |
1931 | ||
1932 | /* A noswitch_section_callback for tls_comm_section. */ | |
f937cbd7 | 1933 | |
6211a3e6 | 1934 | static bool |
102e3995 | 1935 | emit_tls_common (tree decl ATTRIBUTE_UNUSED, |
1936 | const char *name ATTRIBUTE_UNUSED, | |
1937 | unsigned HOST_WIDE_INT size ATTRIBUTE_UNUSED, | |
1938 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED) | |
f937cbd7 | 1939 | { |
102e3995 | 1940 | #ifdef ASM_OUTPUT_TLS_COMMON |
1941 | ASM_OUTPUT_TLS_COMMON (asm_out_file, decl, name, size); | |
1942 | return true; | |
6211a3e6 | 1943 | #else |
102e3995 | 1944 | sorry ("thread-local COMMON data not implemented"); |
1945 | return true; | |
b7fdac4b | 1946 | #endif |
102e3995 | 1947 | } |
f937cbd7 | 1948 | |
102e3995 | 1949 | /* Assemble DECL given that it belongs in SECTION_NOSWITCH section SECT. |
1950 | NAME is the name of DECL's SYMBOL_REF. */ | |
e8732146 | 1951 | |
102e3995 | 1952 | static void |
1953 | assemble_noswitch_variable (tree decl, const char *name, section *sect) | |
1954 | { | |
1955 | unsigned HOST_WIDE_INT size, rounded; | |
5626f4cd | 1956 | |
102e3995 | 1957 | size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); |
1958 | rounded = size; | |
f937cbd7 | 1959 | |
102e3995 | 1960 | /* Don't allocate zero bytes of common, |
1961 | since that means "undefined external" in the linker. */ | |
1962 | if (size == 0) | |
1963 | rounded = 1; | |
1964 | ||
1965 | /* Round size up to multiple of BIGGEST_ALIGNMENT bits | |
1966 | so that each uninitialized object starts on such a boundary. */ | |
1967 | rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1; | |
1968 | rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
1969 | * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); | |
1970 | ||
1971 | if (!sect->noswitch.callback (decl, name, size, rounded) | |
1972 | && (unsigned HOST_WIDE_INT) DECL_ALIGN_UNIT (decl) > rounded) | |
1973 | warning (0, "requested alignment for %q+D is greater than " | |
1974 | "implemented alignment of %wu", decl, rounded); | |
f937cbd7 | 1975 | } |
1976 | ||
f2d0e9f1 | 1977 | /* A subroutine of assemble_variable. Output the label and contents of |
1978 | DECL, whose address is a SYMBOL_REF with name NAME. DONT_OUTPUT_DATA | |
1979 | is as for assemble_variable. */ | |
1980 | ||
1981 | static void | |
1982 | assemble_variable_contents (tree decl, const char *name, | |
1983 | bool dont_output_data) | |
1984 | { | |
1985 | /* Do any machine/system dependent processing of the object. */ | |
1986 | #ifdef ASM_DECLARE_OBJECT_NAME | |
1987 | last_assemble_variable_decl = decl; | |
1988 | ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl); | |
1989 | #else | |
1990 | /* Standard thing is just output label for the object. */ | |
1991 | ASM_OUTPUT_LABEL (asm_out_file, name); | |
1992 | #endif /* ASM_DECLARE_OBJECT_NAME */ | |
1993 | ||
1994 | if (!dont_output_data) | |
1995 | { | |
1996 | if (DECL_INITIAL (decl) | |
1997 | && DECL_INITIAL (decl) != error_mark_node | |
1998 | && !initializer_zerop (DECL_INITIAL (decl))) | |
1999 | /* Output the actual data. */ | |
2000 | output_constant (DECL_INITIAL (decl), | |
2001 | tree_low_cst (DECL_SIZE_UNIT (decl), 1), | |
2002 | DECL_ALIGN (decl)); | |
2003 | else | |
2004 | /* Leave space for it. */ | |
2005 | assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1)); | |
2006 | } | |
2007 | } | |
2008 | ||
38475469 | 2009 | /* Initialize emulated tls object TO, which refers to TLS variable |
2010 | DECL and is initialized by PROXY. */ | |
2011 | ||
2012 | tree | |
2013 | default_emutls_var_init (tree to, tree decl, tree proxy) | |
2014 | { | |
2015 | VEC(constructor_elt,gc) *v = VEC_alloc (constructor_elt, gc, 4); | |
2016 | constructor_elt *elt; | |
2017 | tree type = TREE_TYPE (to); | |
2018 | tree field = TYPE_FIELDS (type); | |
2019 | ||
2020 | elt = VEC_quick_push (constructor_elt, v, NULL); | |
2021 | elt->index = field; | |
2022 | elt->value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl)); | |
2023 | ||
2024 | elt = VEC_quick_push (constructor_elt, v, NULL); | |
2025 | field = TREE_CHAIN (field); | |
2026 | elt->index = field; | |
2027 | elt->value = build_int_cst (TREE_TYPE (field), | |
2028 | DECL_ALIGN_UNIT (decl)); | |
2029 | ||
2030 | elt = VEC_quick_push (constructor_elt, v, NULL); | |
2031 | field = TREE_CHAIN (field); | |
2032 | elt->index = field; | |
2033 | elt->value = null_pointer_node; | |
2034 | ||
2035 | elt = VEC_quick_push (constructor_elt, v, NULL); | |
2036 | field = TREE_CHAIN (field); | |
2037 | elt->index = field; | |
2038 | elt->value = proxy; | |
2039 | ||
2040 | return build_constructor (type, v); | |
2041 | } | |
2042 | ||
5243fbff | 2043 | /* Assemble everything that is needed for a variable or function declaration. |
2044 | Not used for automatic variables, and not used for function definitions. | |
2045 | Should not be called for variables of incomplete structure type. | |
2046 | ||
2047 | TOP_LEVEL is nonzero if this variable has file scope. | |
2048 | AT_END is nonzero if this is the special handling, at end of compilation, | |
82e162bb | 2049 | to define things that have had only tentative definitions. |
2050 | DONT_OUTPUT_DATA if nonzero means don't actually output the | |
2051 | initial value (that will be done by the caller). */ | |
5243fbff | 2052 | |
2053 | void | |
3180a54f | 2054 | assemble_variable (tree decl, int top_level ATTRIBUTE_UNUSED, |
2055 | int at_end ATTRIBUTE_UNUSED, int dont_output_data) | |
5243fbff | 2056 | { |
19cb6b50 | 2057 | const char *name; |
102e3995 | 2058 | rtx decl_rtl, symbol; |
2059 | section *sect; | |
5243fbff | 2060 | |
9dda1f80 | 2061 | if (! targetm.have_tls |
2062 | && TREE_CODE (decl) == VAR_DECL | |
2063 | && DECL_THREAD_LOCAL_P (decl)) | |
2064 | { | |
2065 | tree to = emutls_decl (decl); | |
2066 | ||
2067 | /* If this variable is defined locally, then we need to initialize the | |
2068 | control structure with size and alignment information. We do this | |
2069 | at the last moment because tentative definitions can take a locally | |
2070 | defined but uninitialized variable and initialize it later, which | |
2071 | would result in incorrect contents. */ | |
2072 | if (! DECL_EXTERNAL (to) | |
2073 | && (! DECL_COMMON (to) | |
2074 | || (DECL_INITIAL (decl) | |
2075 | && DECL_INITIAL (decl) != error_mark_node))) | |
2076 | { | |
38475469 | 2077 | DECL_INITIAL (to) = targetm.emutls.var_init |
2078 | (to, decl, get_emutls_init_templ_addr (decl)); | |
9dda1f80 | 2079 | |
2080 | /* Make sure the template is marked as needed early enough. | |
2081 | Without this, if the variable is placed in a | |
2082 | section-anchored block, the template will only be marked | |
2083 | when it's too late. */ | |
2084 | record_references_in_initializer (to); | |
2085 | } | |
2086 | ||
2087 | decl = to; | |
2088 | } | |
2089 | ||
14a4bf15 | 2090 | last_assemble_variable_decl = 0; |
2091 | ||
f9302b44 | 2092 | /* Normally no need to say anything here for external references, |
c3418f42 | 2093 | since assemble_external is called by the language-specific code |
f9302b44 | 2094 | when a declaration is first seen. */ |
5243fbff | 2095 | |
486a79cd | 2096 | if (DECL_EXTERNAL (decl)) |
5243fbff | 2097 | return; |
2098 | ||
2099 | /* Output no assembler code for a function declaration. | |
2100 | Only definitions of functions output anything. */ | |
2101 | ||
2102 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
2103 | return; | |
2104 | ||
9dcd5f30 | 2105 | /* Do nothing for global register variables. */ |
8ad4c111 | 2106 | if (DECL_RTL_SET_P (decl) && REG_P (DECL_RTL (decl))) |
9dcd5f30 | 2107 | { |
2108 | TREE_ASM_WRITTEN (decl) = 1; | |
2109 | return; | |
2110 | } | |
2111 | ||
5243fbff | 2112 | /* If type was incomplete when the variable was declared, |
2113 | see if it is complete now. */ | |
2114 | ||
2115 | if (DECL_SIZE (decl) == 0) | |
2116 | layout_decl (decl, 0); | |
2117 | ||
2118 | /* Still incomplete => don't allocate it; treat the tentative defn | |
2119 | (which is what it must have been) as an `extern' reference. */ | |
2120 | ||
82e162bb | 2121 | if (!dont_output_data && DECL_SIZE (decl) == 0) |
5243fbff | 2122 | { |
3cf8b391 | 2123 | error ("storage size of %q+D isn%'t known", decl); |
cd0c9d9f | 2124 | TREE_ASM_WRITTEN (decl) = 1; |
5243fbff | 2125 | return; |
2126 | } | |
2127 | ||
2128 | /* The first declaration of a variable that comes through this function | |
2129 | decides whether it is global (in C, has external linkage) | |
2130 | or local (in C, has internal linkage). So do nothing more | |
2131 | if this function has already run. */ | |
2132 | ||
2133 | if (TREE_ASM_WRITTEN (decl)) | |
2134 | return; | |
2135 | ||
7811991d | 2136 | /* Make sure targetm.encode_section_info is invoked before we set |
2137 | ASM_WRITTEN. */ | |
30459ad0 | 2138 | decl_rtl = DECL_RTL (decl); |
b7fdac4b | 2139 | |
5243fbff | 2140 | TREE_ASM_WRITTEN (decl) = 1; |
2141 | ||
482465ac | 2142 | /* Do no output if -fsyntax-only. */ |
2143 | if (flag_syntax_only) | |
2144 | return; | |
2145 | ||
44734bb7 | 2146 | app_disable (); |
5243fbff | 2147 | |
02e7a332 | 2148 | if (! dont_output_data |
2149 | && ! host_integerp (DECL_SIZE_UNIT (decl), 1)) | |
82e162bb | 2150 | { |
3cf8b391 | 2151 | error ("size of variable %q+D is too large", decl); |
af48ae2d | 2152 | return; |
5243fbff | 2153 | } |
2154 | ||
f2d0e9f1 | 2155 | gcc_assert (MEM_P (decl_rtl)); |
2156 | gcc_assert (GET_CODE (XEXP (decl_rtl, 0)) == SYMBOL_REF); | |
102e3995 | 2157 | symbol = XEXP (decl_rtl, 0); |
2158 | name = XSTR (symbol, 0); | |
3cad5dd7 | 2159 | if (TREE_PUBLIC (decl) && DECL_NAME (decl)) |
2160 | notice_global_symbol (decl); | |
2f6cfdb5 | 2161 | |
e13a110e | 2162 | /* Compute the alignment of this data. */ |
2163 | ||
d5a2a489 | 2164 | align_variable (decl, dont_output_data); |
2165 | set_mem_align (decl_rtl, DECL_ALIGN (decl)); | |
e13a110e | 2166 | |
01694f08 | 2167 | if (TREE_PUBLIC (decl)) |
2168 | maybe_assemble_visibility (decl); | |
2169 | ||
9423c9b7 | 2170 | if (DECL_PRESERVE_P (decl)) |
2171 | targetm.asm_out.mark_decl_preserved (name); | |
2172 | ||
5243fbff | 2173 | /* First make the assembler name(s) global if appropriate. */ |
102e3995 | 2174 | sect = get_variable_section (decl, false); |
2175 | if (TREE_PUBLIC (decl) | |
102e3995 | 2176 | && (sect->common.flags & SECTION_COMMON) == 0) |
1fbd58a2 | 2177 | globalize_decl (decl); |
5243fbff | 2178 | |
e8732146 | 2179 | /* Output any data that we will need to use the address of. */ |
f2d0e9f1 | 2180 | if (DECL_INITIAL (decl) && DECL_INITIAL (decl) != error_mark_node) |
2181 | output_addressed_constants (DECL_INITIAL (decl)); | |
5243fbff | 2182 | |
4202afe2 | 2183 | /* dbxout.c needs to know this. */ |
841b1537 | 2184 | if (sect && (sect->common.flags & SECTION_CODE) != 0) |
4202afe2 | 2185 | DECL_IN_TEXT_SECTION (decl) = 1; |
2186 | ||
f2d0e9f1 | 2187 | /* If the decl is part of an object_block, make sure that the decl |
2188 | has been positioned within its block, but do not write out its | |
2189 | definition yet. output_object_blocks will do that later. */ | |
6617cbc1 | 2190 | if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol)) |
5243fbff | 2191 | { |
f2d0e9f1 | 2192 | gcc_assert (!dont_output_data); |
102e3995 | 2193 | place_block_symbol (symbol); |
f2d0e9f1 | 2194 | } |
102e3995 | 2195 | else if (SECTION_STYLE (sect) == SECTION_NOSWITCH) |
2196 | assemble_noswitch_variable (decl, name, sect); | |
f2d0e9f1 | 2197 | else |
2198 | { | |
102e3995 | 2199 | switch_to_section (sect); |
d5a2a489 | 2200 | if (DECL_ALIGN (decl) > BITS_PER_UNIT) |
f2d0e9f1 | 2201 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (DECL_ALIGN_UNIT (decl))); |
2202 | assemble_variable_contents (decl, name, dont_output_data); | |
5243fbff | 2203 | } |
5243fbff | 2204 | } |
2205 | ||
48142dc0 | 2206 | /* Return 1 if type TYPE contains any pointers. */ |
2207 | ||
2208 | static int | |
3180a54f | 2209 | contains_pointers_p (tree type) |
48142dc0 | 2210 | { |
2211 | switch (TREE_CODE (type)) | |
2212 | { | |
2213 | case POINTER_TYPE: | |
2214 | case REFERENCE_TYPE: | |
2215 | /* I'm not sure whether OFFSET_TYPE needs this treatment, | |
2216 | so I'll play safe and return 1. */ | |
2217 | case OFFSET_TYPE: | |
2218 | return 1; | |
2219 | ||
2220 | case RECORD_TYPE: | |
2221 | case UNION_TYPE: | |
2222 | case QUAL_UNION_TYPE: | |
2223 | { | |
2224 | tree fields; | |
2225 | /* For a type that has fields, see if the fields have pointers. */ | |
2226 | for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields)) | |
638cce0b | 2227 | if (TREE_CODE (fields) == FIELD_DECL |
2228 | && contains_pointers_p (TREE_TYPE (fields))) | |
48142dc0 | 2229 | return 1; |
2230 | return 0; | |
2231 | } | |
2232 | ||
2233 | case ARRAY_TYPE: | |
2234 | /* An array type contains pointers if its element type does. */ | |
2235 | return contains_pointers_p (TREE_TYPE (type)); | |
2236 | ||
2237 | default: | |
2238 | return 0; | |
2239 | } | |
2240 | } | |
2241 | ||
6329636b | 2242 | /* We delay assemble_external processing until |
e9f08e82 | 2243 | the compilation unit is finalized. This is the best we can do for |
2244 | right now (i.e. stage 3 of GCC 4.0) - the right thing is to delay | |
2245 | it all the way to final. See PR 17982 for further discussion. */ | |
2246 | static GTY(()) tree pending_assemble_externals; | |
2247 | ||
73533af5 | 2248 | #ifdef ASM_OUTPUT_EXTERNAL |
2249 | /* True if DECL is a function decl for which no out-of-line copy exists. | |
2250 | It is assumed that DECL's assembler name has been set. */ | |
2251 | ||
2252 | static bool | |
2253 | incorporeal_function_p (tree decl) | |
2254 | { | |
2255 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl)) | |
2256 | { | |
2257 | const char *name; | |
2258 | ||
2259 | if (DECL_BUILT_IN_CLASS (decl) == BUILT_IN_NORMAL | |
2260 | && DECL_FUNCTION_CODE (decl) == BUILT_IN_ALLOCA) | |
2261 | return true; | |
2262 | ||
2263 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
1c47b3e8 | 2264 | if (is_builtin_name (name)) |
73533af5 | 2265 | return true; |
2266 | } | |
2267 | return false; | |
2268 | } | |
e9f08e82 | 2269 | |
2270 | /* Actually do the tests to determine if this is necessary, and invoke | |
2271 | ASM_OUTPUT_EXTERNAL. */ | |
2272 | static void | |
2273 | assemble_external_real (tree decl) | |
2274 | { | |
2275 | rtx rtl = DECL_RTL (decl); | |
2276 | ||
2277 | if (MEM_P (rtl) && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF | |
2278 | && !SYMBOL_REF_USED (XEXP (rtl, 0)) | |
2279 | && !incorporeal_function_p (decl)) | |
2280 | { | |
2281 | /* Some systems do require some output. */ | |
2282 | SYMBOL_REF_USED (XEXP (rtl, 0)) = 1; | |
2283 | ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0)); | |
2284 | } | |
2285 | } | |
2286 | #endif | |
2287 | ||
2288 | void | |
2289 | process_pending_assemble_externals (void) | |
2290 | { | |
2291 | #ifdef ASM_OUTPUT_EXTERNAL | |
2292 | tree list; | |
2293 | for (list = pending_assemble_externals; list; list = TREE_CHAIN (list)) | |
2294 | assemble_external_real (TREE_VALUE (list)); | |
2295 | ||
2296 | pending_assemble_externals = 0; | |
73533af5 | 2297 | #endif |
e9f08e82 | 2298 | } |
73533af5 | 2299 | |
d36229a0 | 2300 | /* This TREE_LIST contains any weak symbol declarations waiting |
2301 | to be emitted. */ | |
2302 | static GTY(()) tree weak_decls; | |
2303 | ||
cd186228 | 2304 | /* Output something to declare an external symbol to the assembler, |
2305 | and qualifiers such as weakness. (Most assemblers don't need | |
2306 | extern declaration, so we normally output nothing.) Do nothing if | |
2307 | DECL is not external. */ | |
5243fbff | 2308 | |
2309 | void | |
3180a54f | 2310 | assemble_external (tree decl ATTRIBUTE_UNUSED) |
5243fbff | 2311 | { |
49ee78f1 | 2312 | /* Because most platforms do not define ASM_OUTPUT_EXTERNAL, the |
2313 | main body of this code is only rarely exercised. To provide some | |
2314 | testing, on all platforms, we make sure that the ASM_OUT_FILE is | |
2315 | open. If it's not, we should not be calling this function. */ | |
e9f08e82 | 2316 | gcc_assert (asm_out_file); |
49ee78f1 | 2317 | |
e9f08e82 | 2318 | if (!DECL_P (decl) || !DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl)) |
2319 | return; | |
a6e4a944 | 2320 | |
cd186228 | 2321 | /* We want to output annotation for weak and external symbols at |
2322 | very last to check if they are references or not. */ | |
2323 | ||
2324 | if (SUPPORTS_WEAK && DECL_WEAK (decl) | |
2325 | /* TREE_STATIC is a weird and abused creature which is not | |
2326 | generally the right test for whether an entity has been | |
2327 | locally emitted, inlined or otherwise not-really-extern, but | |
2328 | for declarations that can be weak, it happens to be | |
2329 | match. */ | |
a7bc9181 | 2330 | && !TREE_STATIC (decl) |
2331 | && tree_find_value (weak_decls, decl) == NULL_TREE) | |
2332 | weak_decls = tree_cons (NULL, decl, weak_decls); | |
d36229a0 | 2333 | |
cd186228 | 2334 | #ifdef ASM_OUTPUT_EXTERNAL |
a7bc9181 | 2335 | if (tree_find_value (pending_assemble_externals, decl) == NULL_TREE) |
2336 | pending_assemble_externals = tree_cons (NULL, decl, | |
2337 | pending_assemble_externals); | |
5243fbff | 2338 | #endif |
2339 | } | |
2340 | ||
2341 | /* Similar, for calling a library function FUN. */ | |
2342 | ||
2343 | void | |
864af209 | 2344 | assemble_external_libcall (rtx fun) |
5243fbff | 2345 | { |
b54842d8 | 2346 | /* Declare library function name external when first used, if nec. */ |
2347 | if (! SYMBOL_REF_USED (fun)) | |
5243fbff | 2348 | { |
b54842d8 | 2349 | SYMBOL_REF_USED (fun) = 1; |
883b2e73 | 2350 | targetm.asm_out.external_libcall (fun); |
5243fbff | 2351 | } |
5243fbff | 2352 | } |
2353 | ||
5243fbff | 2354 | /* Assemble a label named NAME. */ |
2355 | ||
2356 | void | |
3180a54f | 2357 | assemble_label (const char *name) |
5243fbff | 2358 | { |
b54842d8 | 2359 | ASM_OUTPUT_LABEL (asm_out_file, name); |
5243fbff | 2360 | } |
2361 | ||
4490a821 | 2362 | /* Set the symbol_referenced flag for ID. */ |
f54ed8bc | 2363 | void |
3180a54f | 2364 | mark_referenced (tree id) |
f54ed8bc | 2365 | { |
f54ed8bc | 2366 | TREE_SYMBOL_REFERENCED (id) = 1; |
2367 | } | |
2368 | ||
4490a821 | 2369 | /* Set the symbol_referenced flag for DECL and notify callgraph. */ |
2370 | void | |
2371 | mark_decl_referenced (tree decl) | |
2372 | { | |
2373 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
e907e77f | 2374 | { |
880afb80 | 2375 | /* Extern inline functions don't become needed when referenced. |
2376 | If we know a method will be emitted in other TU and no new | |
2377 | functions can be marked reachable, just use the external | |
2378 | definition. */ | |
2379 | struct cgraph_node *node = cgraph_node (decl); | |
2380 | if (!DECL_EXTERNAL (decl) | |
2381 | && (!node->local.vtable_method || !cgraph_global_info_ready | |
2382 | || !node->local.finalized)) | |
2383 | cgraph_mark_needed_node (node); | |
e907e77f | 2384 | } |
4490a821 | 2385 | else if (TREE_CODE (decl) == VAR_DECL) |
c1dcd13c | 2386 | { |
1d416bd7 | 2387 | struct varpool_node *node = varpool_node (decl); |
2388 | varpool_mark_needed_node (node); | |
c1dcd13c | 2389 | /* C++ frontend use mark_decl_references to force COMDAT variables |
2390 | to be output that might appear dead otherwise. */ | |
2391 | node->force_output = true; | |
2392 | } | |
4490a821 | 2393 | /* else do nothing - we can get various sorts of CST nodes here, |
2394 | which do not need to be marked. */ | |
2395 | } | |
2396 | ||
c22f9090 | 2397 | |
2398 | /* Follow the IDENTIFIER_TRANSPARENT_ALIAS chain starting at *ALIAS | |
2399 | until we find an identifier that is not itself a transparent alias. | |
2400 | Modify the alias passed to it by reference (and all aliases on the | |
2401 | way to the ultimate target), such that they do not have to be | |
2402 | followed again, and return the ultimate target of the alias | |
2403 | chain. */ | |
2404 | ||
f4a30bd7 | 2405 | static inline tree |
2406 | ultimate_transparent_alias_target (tree *alias) | |
2407 | { | |
2408 | tree target = *alias; | |
2409 | ||
2410 | if (IDENTIFIER_TRANSPARENT_ALIAS (target)) | |
2411 | { | |
2412 | gcc_assert (TREE_CHAIN (target)); | |
2413 | target = ultimate_transparent_alias_target (&TREE_CHAIN (target)); | |
2414 | gcc_assert (! IDENTIFIER_TRANSPARENT_ALIAS (target) | |
2415 | && ! TREE_CHAIN (target)); | |
2416 | *alias = target; | |
2417 | } | |
2418 | ||
2419 | return target; | |
2420 | } | |
2421 | ||
48126f0c | 2422 | /* Output to FILE (an assembly file) a reference to NAME. If NAME |
2423 | starts with a *, the rest of NAME is output verbatim. Otherwise | |
2424 | NAME is transformed in a target-specific way (usually by the | |
2425 | addition of an underscore). */ | |
2426 | ||
2427 | void | |
2428 | assemble_name_raw (FILE *file, const char *name) | |
2429 | { | |
2430 | if (name[0] == '*') | |
2431 | fputs (&name[1], file); | |
2432 | else | |
2433 | ASM_OUTPUT_LABELREF (file, name); | |
2434 | } | |
2435 | ||
2436 | /* Like assemble_name_raw, but should be used when NAME might refer to | |
2437 | an entity that is also represented as a tree (like a function or | |
2438 | variable). If NAME does refer to such an entity, that entity will | |
2439 | be marked as referenced. */ | |
5243fbff | 2440 | |
2441 | void | |
3180a54f | 2442 | assemble_name (FILE *file, const char *name) |
5243fbff | 2443 | { |
6e1d237a | 2444 | const char *real_name; |
6efd403b | 2445 | tree id; |
a33bd46d | 2446 | |
6fb33aa0 | 2447 | real_name = targetm.strip_name_encoding (name); |
a8ac1177 | 2448 | |
6efd403b | 2449 | id = maybe_get_identifier (real_name); |
2450 | if (id) | |
f4a30bd7 | 2451 | { |
98dab141 | 2452 | tree id_orig = id; |
2453 | ||
f4a30bd7 | 2454 | mark_referenced (id); |
2455 | ultimate_transparent_alias_target (&id); | |
98dab141 | 2456 | if (id != id_orig) |
2457 | name = IDENTIFIER_POINTER (id); | |
f4a30bd7 | 2458 | gcc_assert (! TREE_CHAIN (id)); |
2459 | } | |
aaeecbd4 | 2460 | |
48126f0c | 2461 | assemble_name_raw (file, name); |
5243fbff | 2462 | } |
2463 | ||
2464 | /* Allocate SIZE bytes writable static space with a gensym name | |
2465 | and return an RTX to refer to its address. */ | |
2466 | ||
2467 | rtx | |
3180a54f | 2468 | assemble_static_space (unsigned HOST_WIDE_INT size) |
5243fbff | 2469 | { |
2470 | char name[12]; | |
44acf429 | 2471 | const char *namestring; |
5243fbff | 2472 | rtx x; |
5243fbff | 2473 | |
5243fbff | 2474 | ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno); |
2475 | ++const_labelno; | |
ec6cb94a | 2476 | namestring = ggc_strdup (name); |
5243fbff | 2477 | |
b54842d8 | 2478 | x = gen_rtx_SYMBOL_REF (Pmode, namestring); |
001be062 | 2479 | SYMBOL_REF_FLAGS (x) = SYMBOL_FLAG_LOCAL; |
649d8da6 | 2480 | |
0dbd1c74 | 2481 | #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL |
b54842d8 | 2482 | ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size, |
2483 | BIGGEST_ALIGNMENT); | |
0dbd1c74 | 2484 | #else |
5243fbff | 2485 | #ifdef ASM_OUTPUT_ALIGNED_LOCAL |
b54842d8 | 2486 | ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT); |
5243fbff | 2487 | #else |
77d71bdb | 2488 | { |
2489 | /* Round size up to multiple of BIGGEST_ALIGNMENT bits | |
2490 | so that each uninitialized object starts on such a boundary. */ | |
1be87b72 | 2491 | /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */ |
d716c068 | 2492 | unsigned HOST_WIDE_INT rounded ATTRIBUTE_UNUSED |
1b988e85 | 2493 | = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1) |
2494 | / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) | |
2495 | * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); | |
77d71bdb | 2496 | ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded); |
2497 | } | |
0dbd1c74 | 2498 | #endif |
5243fbff | 2499 | #endif |
2500 | return x; | |
2501 | } | |
2502 | ||
2503 | /* Assemble the static constant template for function entry trampolines. | |
2504 | This is done at most once per compilation. | |
2505 | Returns an RTX for the address of the template. */ | |
2506 | ||
4ee9c684 | 2507 | static GTY(()) rtx initial_trampoline; |
2508 | ||
ad3430b8 | 2509 | #ifdef TRAMPOLINE_TEMPLATE |
5243fbff | 2510 | rtx |
3180a54f | 2511 | assemble_trampoline_template (void) |
5243fbff | 2512 | { |
2513 | char label[256]; | |
a23072e2 | 2514 | const char *name; |
5243fbff | 2515 | int align; |
001be062 | 2516 | rtx symbol; |
5243fbff | 2517 | |
4ee9c684 | 2518 | if (initial_trampoline) |
2519 | return initial_trampoline; | |
2520 | ||
b93de441 | 2521 | /* By default, put trampoline templates in read-only data section. */ |
7aee14a2 | 2522 | |
b93de441 | 2523 | #ifdef TRAMPOLINE_SECTION |
2f14b1f9 | 2524 | switch_to_section (TRAMPOLINE_SECTION); |
b93de441 | 2525 | #else |
2f14b1f9 | 2526 | switch_to_section (readonly_data_section); |
b93de441 | 2527 | #endif |
7aee14a2 | 2528 | |
5243fbff | 2529 | /* Write the assembler code to define one. */ |
3864cf09 | 2530 | align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT); |
5243fbff | 2531 | if (align > 0) |
77ec0c64 | 2532 | { |
2533 | ASM_OUTPUT_ALIGN (asm_out_file, align); | |
2534 | } | |
5243fbff | 2535 | |
883b2e73 | 2536 | targetm.asm_out.internal_label (asm_out_file, "LTRAMP", 0); |
5243fbff | 2537 | TRAMPOLINE_TEMPLATE (asm_out_file); |
2538 | ||
2539 | /* Record the rtl to refer to it. */ | |
2540 | ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0); | |
ec6cb94a | 2541 | name = ggc_strdup (label); |
001be062 | 2542 | symbol = gen_rtx_SYMBOL_REF (Pmode, name); |
2543 | SYMBOL_REF_FLAGS (symbol) = SYMBOL_FLAG_LOCAL; | |
2544 | ||
4ee9c684 | 2545 | initial_trampoline = gen_rtx_MEM (BLKmode, symbol); |
2546 | set_mem_align (initial_trampoline, TRAMPOLINE_ALIGNMENT); | |
2547 | ||
2548 | return initial_trampoline; | |
5243fbff | 2549 | } |
ad3430b8 | 2550 | #endif |
5243fbff | 2551 | \f |
09d688ff | 2552 | /* A and B are either alignments or offsets. Return the minimum alignment |
2553 | that may be assumed after adding the two together. */ | |
2554 | ||
2555 | static inline unsigned | |
3180a54f | 2556 | min_align (unsigned int a, unsigned int b) |
09d688ff | 2557 | { |
2558 | return (a | b) & -(a | b); | |
2559 | } | |
5243fbff | 2560 | |
58356836 | 2561 | /* Return the assembler directive for creating a given kind of integer |
2562 | object. SIZE is the number of bytes in the object and ALIGNED_P | |
2563 | indicates whether it is known to be aligned. Return NULL if the | |
2564 | assembly dialect has no such directive. | |
5243fbff | 2565 | |
58356836 | 2566 | The returned string should be printed at the start of a new line and |
2567 | be followed immediately by the object's initial value. */ | |
2568 | ||
2569 | const char * | |
3180a54f | 2570 | integer_asm_op (int size, int aligned_p) |
5243fbff | 2571 | { |
58356836 | 2572 | struct asm_int_op *ops; |
5243fbff | 2573 | |
58356836 | 2574 | if (aligned_p) |
2575 | ops = &targetm.asm_out.aligned_op; | |
09d688ff | 2576 | else |
58356836 | 2577 | ops = &targetm.asm_out.unaligned_op; |
2578 | ||
2579 | switch (size) | |
09d688ff | 2580 | { |
58356836 | 2581 | case 1: |
2582 | return targetm.asm_out.byte_op; | |
2583 | case 2: | |
2584 | return ops->hi; | |
2585 | case 4: | |
2586 | return ops->si; | |
2587 | case 8: | |
2588 | return ops->di; | |
2589 | case 16: | |
2590 | return ops->ti; | |
2591 | default: | |
2592 | return NULL; | |
2593 | } | |
2594 | } | |
09d688ff | 2595 | |
58356836 | 2596 | /* Use directive OP to assemble an integer object X. Print OP at the |
2597 | start of the line, followed immediately by the value of X. */ | |
09d688ff | 2598 | |
58356836 | 2599 | void |
3180a54f | 2600 | assemble_integer_with_op (const char *op, rtx x) |
58356836 | 2601 | { |
2602 | fputs (op, asm_out_file); | |
2603 | output_addr_const (asm_out_file, x); | |
2604 | fputc ('\n', asm_out_file); | |
2605 | } | |
5243fbff | 2606 | |
58356836 | 2607 | /* The default implementation of the asm_out.integer target hook. */ |
5243fbff | 2608 | |
58356836 | 2609 | bool |
3180a54f | 2610 | default_assemble_integer (rtx x ATTRIBUTE_UNUSED, |
2611 | unsigned int size ATTRIBUTE_UNUSED, | |
2612 | int aligned_p ATTRIBUTE_UNUSED) | |
58356836 | 2613 | { |
2614 | const char *op = integer_asm_op (size, aligned_p); | |
3e8b0d55 | 2615 | /* Avoid GAS bugs for large values. Specifically negative values whose |
2616 | absolute value fits in a bfd_vma, but not in a bfd_signed_vma. */ | |
2617 | if (size > UNITS_PER_WORD && size > POINTER_SIZE / BITS_PER_UNIT) | |
95326167 | 2618 | return false; |
58356836 | 2619 | return op && (assemble_integer_with_op (op, x), true); |
2620 | } | |
5243fbff | 2621 | |
58356836 | 2622 | /* Assemble the integer constant X into an object of SIZE bytes. ALIGN is |
2623 | the alignment of the integer in bits. Return 1 if we were able to output | |
a53ff4c1 | 2624 | the constant, otherwise 0. We must be able to output the constant, |
2625 | if FORCE is nonzero. */ | |
5243fbff | 2626 | |
58356836 | 2627 | bool |
3180a54f | 2628 | assemble_integer (rtx x, unsigned int size, unsigned int align, int force) |
58356836 | 2629 | { |
2630 | int aligned_p; | |
5243fbff | 2631 | |
58356836 | 2632 | aligned_p = (align >= MIN (size * BITS_PER_UNIT, BIGGEST_ALIGNMENT)); |
5243fbff | 2633 | |
58356836 | 2634 | /* See if the target hook can handle this kind of object. */ |
883b2e73 | 2635 | if (targetm.asm_out.integer (x, size, aligned_p)) |
58356836 | 2636 | return true; |
5243fbff | 2637 | |
58356836 | 2638 | /* If the object is a multi-byte one, try splitting it up. Split |
2639 | it into words it if is multi-word, otherwise split it into bytes. */ | |
2640 | if (size > 1) | |
09d688ff | 2641 | { |
2642 | enum machine_mode omode, imode; | |
58356836 | 2643 | unsigned int subalign; |
2644 | unsigned int subsize, i; | |
b9c74b4d | 2645 | enum mode_class mclass; |
b7fdac4b | 2646 | |
58356836 | 2647 | subsize = size > UNITS_PER_WORD? UNITS_PER_WORD : 1; |
2648 | subalign = MIN (align, subsize * BITS_PER_UNIT); | |
e397ad8e | 2649 | if (GET_CODE (x) == CONST_FIXED) |
2650 | mclass = GET_MODE_CLASS (GET_MODE (x)); | |
2651 | else | |
2652 | mclass = MODE_INT; | |
2653 | ||
2654 | omode = mode_for_size (subsize * BITS_PER_UNIT, mclass, 0); | |
2655 | imode = mode_for_size (size * BITS_PER_UNIT, mclass, 0); | |
09d688ff | 2656 | |
58356836 | 2657 | for (i = 0; i < size; i += subsize) |
09d688ff | 2658 | { |
58356836 | 2659 | rtx partial = simplify_subreg (omode, x, imode, i); |
2660 | if (!partial || !assemble_integer (partial, subsize, subalign, 0)) | |
09d688ff | 2661 | break; |
2662 | } | |
09d688ff | 2663 | if (i == size) |
58356836 | 2664 | return true; |
2665 | ||
2666 | /* If we've printed some of it, but not all of it, there's no going | |
2667 | back now. */ | |
22167fd5 | 2668 | gcc_assert (!i); |
09d688ff | 2669 | } |
2670 | ||
22167fd5 | 2671 | gcc_assert (!force); |
b215c058 | 2672 | |
58356836 | 2673 | return false; |
5243fbff | 2674 | } |
2675 | \f | |
cb9c469a | 2676 | void |
3180a54f | 2677 | assemble_real (REAL_VALUE_TYPE d, enum machine_mode mode, unsigned int align) |
cc190096 | 2678 | { |
6382ea24 | 2679 | long data[4] = {0, 0, 0, 0}; |
b613c3d1 | 2680 | int i; |
2681 | int bitsize, nelts, nunits, units_per; | |
2682 | ||
b8bc42e9 | 2683 | /* This is hairy. We have a quantity of known size. real_to_target |
b613c3d1 | 2684 | will put it into an array of *host* longs, 32 bits per element |
2685 | (even if long is more than 32 bits). We need to determine the | |
2686 | number of array elements that are occupied (nelts) and the number | |
2687 | of *target* min-addressable units that will be occupied in the | |
b8bc42e9 | 2688 | object file (nunits). We cannot assume that 32 divides the |
2689 | mode's bitsize (size * BITS_PER_UNIT) evenly. | |
2690 | ||
2691 | size * BITS_PER_UNIT is used here to make sure that padding bits | |
2692 | (which might appear at either end of the value; real_to_target | |
2693 | will include the padding bits in its output array) are included. */ | |
2694 | ||
2695 | nunits = GET_MODE_SIZE (mode); | |
2696 | bitsize = nunits * BITS_PER_UNIT; | |
b613c3d1 | 2697 | nelts = CEIL (bitsize, 32); |
2698 | units_per = 32 / BITS_PER_UNIT; | |
2699 | ||
2700 | real_to_target (data, &d, mode); | |
2701 | ||
2702 | /* Put out the first word with the specified alignment. */ | |
2703 | assemble_integer (GEN_INT (data[0]), MIN (nunits, units_per), align, 1); | |
2704 | nunits -= units_per; | |
2705 | ||
2706 | /* Subsequent words need only 32-bit alignment. */ | |
2707 | align = min_align (align, 32); | |
2708 | ||
2709 | for (i = 1; i < nelts; i++) | |
5243fbff | 2710 | { |
b613c3d1 | 2711 | assemble_integer (GEN_INT (data[i]), MIN (nunits, units_per), align, 1); |
2712 | nunits -= units_per; | |
5243fbff | 2713 | } |
cc190096 | 2714 | } |
5243fbff | 2715 | \f |
5243fbff | 2716 | /* Given an expression EXP with a constant value, |
2717 | reduce it to the sum of an assembler symbol and an integer. | |
2718 | Store them both in the structure *VALUE. | |
f689eec7 | 2719 | EXP must be reducible. */ |
5243fbff | 2720 | |
fb1e4f4a | 2721 | struct GTY(()) addr_const { |
5243fbff | 2722 | rtx base; |
b05c17ed | 2723 | HOST_WIDE_INT offset; |
5243fbff | 2724 | }; |
2725 | ||
2726 | static void | |
3180a54f | 2727 | decode_addr_const (tree exp, struct addr_const *value) |
5243fbff | 2728 | { |
19cb6b50 | 2729 | tree target = TREE_OPERAND (exp, 0); |
2730 | int offset = 0; | |
2731 | rtx x; | |
5243fbff | 2732 | |
2733 | while (1) | |
2734 | { | |
2735 | if (TREE_CODE (target) == COMPONENT_REF | |
02e7a332 | 2736 | && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0)) |
5d844ba2 | 2737 | |
5243fbff | 2738 | { |
02e7a332 | 2739 | offset += int_byte_position (TREE_OPERAND (target, 1)); |
5243fbff | 2740 | target = TREE_OPERAND (target, 0); |
2741 | } | |
ba04d9d5 | 2742 | else if (TREE_CODE (target) == ARRAY_REF |
2743 | || TREE_CODE (target) == ARRAY_RANGE_REF) | |
5243fbff | 2744 | { |
02e7a332 | 2745 | offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1) |
2746 | * tree_low_cst (TREE_OPERAND (target, 1), 0)); | |
5243fbff | 2747 | target = TREE_OPERAND (target, 0); |
2748 | } | |
2749 | else | |
2750 | break; | |
2751 | } | |
2752 | ||
2753 | switch (TREE_CODE (target)) | |
2754 | { | |
2755 | case VAR_DECL: | |
2756 | case FUNCTION_DECL: | |
2757 | x = DECL_RTL (target); | |
2758 | break; | |
2759 | ||
2760 | case LABEL_DECL: | |
b54842d8 | 2761 | x = gen_rtx_MEM (FUNCTION_MODE, |
514b43f8 | 2762 | gen_rtx_LABEL_REF (Pmode, force_label_rtx (target))); |
5243fbff | 2763 | break; |
2764 | ||
2765 | case REAL_CST: | |
e397ad8e | 2766 | case FIXED_CST: |
5243fbff | 2767 | case STRING_CST: |
2768 | case COMPLEX_CST: | |
2769 | case CONSTRUCTOR: | |
dfaff4ae | 2770 | case INTEGER_CST: |
52dd4e9f | 2771 | x = output_constant_def (target, 1); |
5243fbff | 2772 | break; |
2773 | ||
2774 | default: | |
22167fd5 | 2775 | gcc_unreachable (); |
5243fbff | 2776 | } |
2777 | ||
22167fd5 | 2778 | gcc_assert (MEM_P (x)); |
b54842d8 | 2779 | x = XEXP (x, 0); |
5243fbff | 2780 | |
2781 | value->base = x; | |
2782 | value->offset = offset; | |
2783 | } | |
2784 | \f | |
2785 | /* Uniquize all constants that appear in memory. | |
2786 | Each constant in memory thus far output is recorded | |
2e355795 | 2787 | in `const_desc_table'. */ |
5243fbff | 2788 | |
fb1e4f4a | 2789 | struct GTY(()) constant_descriptor_tree { |
1f3233d1 | 2790 | /* A MEM for the constant. */ |
155b05dc | 2791 | rtx rtl; |
1f3233d1 | 2792 | |
2793 | /* The value of the constant. */ | |
2794 | tree value; | |
a3841d3a | 2795 | |
2796 | /* Hash of value. Computing the hash from value each time | |
2797 | hashfn is called can't work properly, as that means recursive | |
2798 | use of the hash table during hash table expansion. */ | |
2799 | hashval_t hash; | |
5243fbff | 2800 | }; |
2801 | ||
364bde6b | 2802 | static GTY((param_is (struct constant_descriptor_tree))) |
2803 | htab_t const_desc_htab; | |
5243fbff | 2804 | |
3180a54f | 2805 | static struct constant_descriptor_tree * build_constant_desc (tree); |
2806 | static void maybe_output_constant_def_contents (struct constant_descriptor_tree *, int); | |
abf74c5b | 2807 | |
5243fbff | 2808 | /* Compute a hash code for a constant expression. */ |
2809 | ||
364bde6b | 2810 | static hashval_t |
3180a54f | 2811 | const_desc_hash (const void *ptr) |
3393215f | 2812 | { |
aae87fc3 | 2813 | return ((const struct constant_descriptor_tree *)ptr)->hash; |
3393215f | 2814 | } |
2815 | ||
364bde6b | 2816 | static hashval_t |
3180a54f | 2817 | const_hash_1 (const tree exp) |
5243fbff | 2818 | { |
19cb6b50 | 2819 | const char *p; |
364bde6b | 2820 | hashval_t hi; |
3393215f | 2821 | int len, i; |
19cb6b50 | 2822 | enum tree_code code = TREE_CODE (exp); |
5243fbff | 2823 | |
65fc74c1 | 2824 | /* Either set P and LEN to the address and len of something to hash and |
2825 | exit the switch or return a value. */ | |
2826 | ||
2827 | switch (code) | |
5243fbff | 2828 | { |
65fc74c1 | 2829 | case INTEGER_CST: |
2a8a276e | 2830 | p = (char *) &TREE_INT_CST (exp); |
2831 | len = sizeof TREE_INT_CST (exp); | |
65fc74c1 | 2832 | break; |
2833 | ||
2834 | case REAL_CST: | |
3393215f | 2835 | return real_hash (TREE_REAL_CST_PTR (exp)); |
5243fbff | 2836 | |
e397ad8e | 2837 | case FIXED_CST: |
2838 | return fixed_hash (TREE_FIXED_CST_PTR (exp)); | |
2839 | ||
65fc74c1 | 2840 | case STRING_CST: |
a814bad5 | 2841 | p = TREE_STRING_POINTER (exp); |
2842 | len = TREE_STRING_LENGTH (exp); | |
65fc74c1 | 2843 | break; |
2e355795 | 2844 | |
65fc74c1 | 2845 | case COMPLEX_CST: |
3393215f | 2846 | return (const_hash_1 (TREE_REALPART (exp)) * 5 |
2847 | + const_hash_1 (TREE_IMAGPART (exp))); | |
65fc74c1 | 2848 | |
2849 | case CONSTRUCTOR: | |
16037b31 | 2850 | { |
c75b4594 | 2851 | unsigned HOST_WIDE_INT idx; |
2852 | tree value; | |
b215c058 | 2853 | |
16037b31 | 2854 | hi = 5 + int_size_in_bytes (TREE_TYPE (exp)); |
b215c058 | 2855 | |
c75b4594 | 2856 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value) |
2857 | if (value) | |
2858 | hi = hi * 603 + const_hash_1 (value); | |
b215c058 | 2859 | |
16037b31 | 2860 | return hi; |
2861 | } | |
5243fbff | 2862 | |
65fc74c1 | 2863 | case ADDR_EXPR: |
feb489ec | 2864 | case FDESC_EXPR: |
65fc74c1 | 2865 | { |
2866 | struct addr_const value; | |
2867 | ||
2868 | decode_addr_const (exp, &value); | |
22167fd5 | 2869 | switch (GET_CODE (value.base)) |
65fc74c1 | 2870 | { |
22167fd5 | 2871 | case SYMBOL_REF: |
65fc74c1 | 2872 | /* Don't hash the address of the SYMBOL_REF; |
2873 | only use the offset and the symbol name. */ | |
2874 | hi = value.offset; | |
2875 | p = XSTR (value.base, 0); | |
2876 | for (i = 0; p[i] != 0; i++) | |
2877 | hi = ((hi * 613) + (unsigned) (p[i])); | |
22167fd5 | 2878 | break; |
2879 | ||
2880 | case LABEL_REF: | |
2881 | hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13; | |
2882 | break; | |
2883 | ||
2884 | default: | |
2885 | gcc_unreachable (); | |
65fc74c1 | 2886 | } |
65fc74c1 | 2887 | } |
5243fbff | 2888 | return hi; |
65fc74c1 | 2889 | |
2890 | case PLUS_EXPR: | |
0de36bdb | 2891 | case POINTER_PLUS_EXPR: |
65fc74c1 | 2892 | case MINUS_EXPR: |
3393215f | 2893 | return (const_hash_1 (TREE_OPERAND (exp, 0)) * 9 |
2894 | + const_hash_1 (TREE_OPERAND (exp, 1))); | |
65fc74c1 | 2895 | |
72dd6141 | 2896 | CASE_CONVERT: |
3393215f | 2897 | return const_hash_1 (TREE_OPERAND (exp, 0)) * 7 + 2; |
b7fdac4b | 2898 | |
0dbd1c74 | 2899 | default: |
1be87b72 | 2900 | /* A language specific constant. Just hash the code. */ |
3393215f | 2901 | return code; |
5243fbff | 2902 | } |
5243fbff | 2903 | |
2358393e | 2904 | /* Compute hashing function. */ |
5243fbff | 2905 | hi = len; |
2906 | for (i = 0; i < len; i++) | |
a92771b8 | 2907 | hi = ((hi * 613) + (unsigned) (p[i])); |
5243fbff | 2908 | |
5243fbff | 2909 | return hi; |
2910 | } | |
5243fbff | 2911 | |
364bde6b | 2912 | /* Wrapper of compare_constant, for the htab interface. */ |
2913 | static int | |
3180a54f | 2914 | const_desc_eq (const void *p1, const void *p2) |
364bde6b | 2915 | { |
45ba1503 | 2916 | const struct constant_descriptor_tree *const c1 |
2917 | = (const struct constant_descriptor_tree *) p1; | |
2918 | const struct constant_descriptor_tree *const c2 | |
2919 | = (const struct constant_descriptor_tree *) p2; | |
a3841d3a | 2920 | if (c1->hash != c2->hash) |
2921 | return 0; | |
2922 | return compare_constant (c1->value, c2->value); | |
364bde6b | 2923 | } |
2924 | ||
1f3233d1 | 2925 | /* Compare t1 and t2, and return 1 only if they are known to result in |
2926 | the same bit pattern on output. */ | |
5243fbff | 2927 | |
1f3233d1 | 2928 | static int |
3180a54f | 2929 | compare_constant (const tree t1, const tree t2) |
5243fbff | 2930 | { |
1f3233d1 | 2931 | enum tree_code typecode; |
5243fbff | 2932 | |
1f3233d1 | 2933 | if (t1 == NULL_TREE) |
2934 | return t2 == NULL_TREE; | |
2935 | if (t2 == NULL_TREE) | |
5243fbff | 2936 | return 0; |
2937 | ||
1f3233d1 | 2938 | if (TREE_CODE (t1) != TREE_CODE (t2)) |
2939 | return 0; | |
65fc74c1 | 2940 | |
1f3233d1 | 2941 | switch (TREE_CODE (t1)) |
5243fbff | 2942 | { |
65fc74c1 | 2943 | case INTEGER_CST: |
5243fbff | 2944 | /* Integer constants are the same only if the same width of type. */ |
1f3233d1 | 2945 | if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2))) |
5243fbff | 2946 | return 0; |
3bd7c304 | 2947 | if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))) |
2948 | return 0; | |
1f3233d1 | 2949 | return tree_int_cst_equal (t1, t2); |
65fc74c1 | 2950 | |
2951 | case REAL_CST: | |
5243fbff | 2952 | /* Real constants are the same only if the same width of type. */ |
1f3233d1 | 2953 | if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2))) |
5243fbff | 2954 | return 0; |
65fc74c1 | 2955 | |
1f3233d1 | 2956 | return REAL_VALUES_IDENTICAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); |
65fc74c1 | 2957 | |
e397ad8e | 2958 | case FIXED_CST: |
2959 | /* Fixed constants are the same only if the same width of type. */ | |
2960 | if (TYPE_PRECISION (TREE_TYPE (t1)) != TYPE_PRECISION (TREE_TYPE (t2))) | |
2961 | return 0; | |
2962 | ||
2963 | return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), TREE_FIXED_CST (t2)); | |
2964 | ||
65fc74c1 | 2965 | case STRING_CST: |
1f3233d1 | 2966 | if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2))) |
5243fbff | 2967 | return 0; |
65fc74c1 | 2968 | |
1f3233d1 | 2969 | return (TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) |
2970 | && ! memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), | |
2971 | TREE_STRING_LENGTH (t1))); | |
5243fbff | 2972 | |
65fc74c1 | 2973 | case COMPLEX_CST: |
1f3233d1 | 2974 | return (compare_constant (TREE_REALPART (t1), TREE_REALPART (t2)) |
2975 | && compare_constant (TREE_IMAGPART (t1), TREE_IMAGPART (t2))); | |
5243fbff | 2976 | |
65fc74c1 | 2977 | case CONSTRUCTOR: |
16037b31 | 2978 | { |
c75b4594 | 2979 | VEC(constructor_elt, gc) *v1, *v2; |
2980 | unsigned HOST_WIDE_INT idx; | |
b215c058 | 2981 | |
16037b31 | 2982 | typecode = TREE_CODE (TREE_TYPE (t1)); |
2983 | if (typecode != TREE_CODE (TREE_TYPE (t2))) | |
2984 | return 0; | |
65fc74c1 | 2985 | |
16037b31 | 2986 | if (typecode == ARRAY_TYPE) |
2987 | { | |
2988 | HOST_WIDE_INT size_1 = int_size_in_bytes (TREE_TYPE (t1)); | |
2989 | /* For arrays, check that the sizes all match. */ | |
2990 | if (TYPE_MODE (TREE_TYPE (t1)) != TYPE_MODE (TREE_TYPE (t2)) | |
2991 | || size_1 == -1 | |
2992 | || size_1 != int_size_in_bytes (TREE_TYPE (t2))) | |
2993 | return 0; | |
2994 | } | |
2995 | else | |
2996 | { | |
2997 | /* For record and union constructors, require exact type | |
2998 | equality. */ | |
2999 | if (TREE_TYPE (t1) != TREE_TYPE (t2)) | |
3000 | return 0; | |
3001 | } | |
8bc122e1 | 3002 | |
c75b4594 | 3003 | v1 = CONSTRUCTOR_ELTS (t1); |
3004 | v2 = CONSTRUCTOR_ELTS (t2); | |
3005 | if (VEC_length (constructor_elt, v1) | |
3006 | != VEC_length (constructor_elt, v2)) | |
3007 | return 0; | |
3008 | ||
3009 | for (idx = 0; idx < VEC_length (constructor_elt, v1); ++idx) | |
16037b31 | 3010 | { |
c75b4594 | 3011 | constructor_elt *c1 = VEC_index (constructor_elt, v1, idx); |
3012 | constructor_elt *c2 = VEC_index (constructor_elt, v2, idx); | |
3013 | ||
16037b31 | 3014 | /* Check that each value is the same... */ |
c75b4594 | 3015 | if (!compare_constant (c1->value, c2->value)) |
16037b31 | 3016 | return 0; |
3017 | /* ... and that they apply to the same fields! */ | |
3018 | if (typecode == ARRAY_TYPE) | |
3019 | { | |
c75b4594 | 3020 | if (!compare_constant (c1->index, c2->index)) |
16037b31 | 3021 | return 0; |
3022 | } | |
3023 | else | |
3024 | { | |
c75b4594 | 3025 | if (c1->index != c2->index) |
16037b31 | 3026 | return 0; |
3027 | } | |
3028 | } | |
b215c058 | 3029 | |
c75b4594 | 3030 | return 1; |
16037b31 | 3031 | } |
8b82837b | 3032 | |
65fc74c1 | 3033 | case ADDR_EXPR: |
feb489ec | 3034 | case FDESC_EXPR: |
65fc74c1 | 3035 | { |
1f3233d1 | 3036 | struct addr_const value1, value2; |
65fc74c1 | 3037 | |
1f3233d1 | 3038 | decode_addr_const (t1, &value1); |
3039 | decode_addr_const (t2, &value2); | |
3040 | return (value1.offset == value2.offset | |
3041 | && strcmp (XSTR (value1.base, 0), XSTR (value2.base, 0)) == 0); | |
65fc74c1 | 3042 | } |
65fc74c1 | 3043 | |
3044 | case PLUS_EXPR: | |
0de36bdb | 3045 | case POINTER_PLUS_EXPR: |
65fc74c1 | 3046 | case MINUS_EXPR: |
341300be | 3047 | case RANGE_EXPR: |
1f3233d1 | 3048 | return (compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)) |
3049 | && compare_constant(TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1))); | |
65fc74c1 | 3050 | |
72dd6141 | 3051 | CASE_CONVERT: |
f2848721 | 3052 | case VIEW_CONVERT_EXPR: |
1f3233d1 | 3053 | return compare_constant (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); |
0dbd1c74 | 3054 | |
3055 | default: | |
1b49e7ef | 3056 | return 0; |
5243fbff | 3057 | } |
3058 | ||
22167fd5 | 3059 | gcc_unreachable (); |
5243fbff | 3060 | } |
3061 | \f | |
1f3233d1 | 3062 | /* Make a copy of the whole tree structure for a constant. This |
3063 | handles the same types of nodes that compare_constant handles. */ | |
e8e4ebd2 | 3064 | |
3065 | static tree | |
3180a54f | 3066 | copy_constant (tree exp) |
e8e4ebd2 | 3067 | { |
3068 | switch (TREE_CODE (exp)) | |
3069 | { | |
38495f14 | 3070 | case ADDR_EXPR: |
3071 | /* For ADDR_EXPR, we do not want to copy the decl whose address | |
3072 | is requested. We do want to copy constants though. */ | |
ce45a448 | 3073 | if (CONSTANT_CLASS_P (TREE_OPERAND (exp, 0))) |
38495f14 | 3074 | return build1 (TREE_CODE (exp), TREE_TYPE (exp), |
3075 | copy_constant (TREE_OPERAND (exp, 0))); | |
3076 | else | |
3077 | return copy_node (exp); | |
3078 | ||
e8e4ebd2 | 3079 | case INTEGER_CST: |
3080 | case REAL_CST: | |
e397ad8e | 3081 | case FIXED_CST: |
e8e4ebd2 | 3082 | case STRING_CST: |
e8e4ebd2 | 3083 | return copy_node (exp); |
3084 | ||
3085 | case COMPLEX_CST: | |
b3f329e3 | 3086 | return build_complex (TREE_TYPE (exp), |
3087 | copy_constant (TREE_REALPART (exp)), | |
e8e4ebd2 | 3088 | copy_constant (TREE_IMAGPART (exp))); |
3089 | ||
3090 | case PLUS_EXPR: | |
0de36bdb | 3091 | case POINTER_PLUS_EXPR: |
e8e4ebd2 | 3092 | case MINUS_EXPR: |
b55f9493 | 3093 | return build2 (TREE_CODE (exp), TREE_TYPE (exp), |
3094 | copy_constant (TREE_OPERAND (exp, 0)), | |
3095 | copy_constant (TREE_OPERAND (exp, 1))); | |
e8e4ebd2 | 3096 | |
72dd6141 | 3097 | CASE_CONVERT: |
5dc8dae0 | 3098 | case VIEW_CONVERT_EXPR: |
e8e4ebd2 | 3099 | return build1 (TREE_CODE (exp), TREE_TYPE (exp), |
3100 | copy_constant (TREE_OPERAND (exp, 0))); | |
3101 | ||
3102 | case CONSTRUCTOR: | |
3103 | { | |
3104 | tree copy = copy_node (exp); | |
c75b4594 | 3105 | VEC(constructor_elt, gc) *v; |
3106 | unsigned HOST_WIDE_INT idx; | |
3107 | tree purpose, value; | |
b215c058 | 3108 | |
c75b4594 | 3109 | v = VEC_alloc(constructor_elt, gc, VEC_length(constructor_elt, |
3110 | CONSTRUCTOR_ELTS (exp))); | |
3111 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, purpose, value) | |
3112 | { | |
3113 | constructor_elt *ce = VEC_quick_push (constructor_elt, v, NULL); | |
3114 | ce->index = purpose; | |
3115 | ce->value = copy_constant (value); | |
3116 | } | |
3117 | CONSTRUCTOR_ELTS (copy) = v; | |
e8e4ebd2 | 3118 | return copy; |
3119 | } | |
3120 | ||
3121 | default: | |
1b49e7ef | 3122 | gcc_unreachable (); |
e8e4ebd2 | 3123 | } |
3124 | } | |
82e162bb | 3125 | \f |
f2d0e9f1 | 3126 | /* Return the alignment of constant EXP in bits. */ |
3127 | ||
3128 | static unsigned int | |
3129 | get_constant_alignment (tree exp) | |
3130 | { | |
3131 | unsigned int align; | |
3132 | ||
3133 | align = TYPE_ALIGN (TREE_TYPE (exp)); | |
3134 | #ifdef CONSTANT_ALIGNMENT | |
3135 | align = CONSTANT_ALIGNMENT (exp, align); | |
3136 | #endif | |
3137 | return align; | |
3138 | } | |
3139 | ||
3140 | /* Return the section into which constant EXP should be placed. */ | |
3141 | ||
3142 | static section * | |
3143 | get_constant_section (tree exp) | |
3144 | { | |
3145 | if (IN_NAMED_SECTION (exp)) | |
3146 | return get_named_section (exp, NULL, compute_reloc_for_constant (exp)); | |
3147 | else | |
3148 | return targetm.asm_out.select_section (exp, | |
3149 | compute_reloc_for_constant (exp), | |
3150 | get_constant_alignment (exp)); | |
3151 | } | |
3152 | ||
3153 | /* Return the size of constant EXP in bytes. */ | |
3154 | ||
3155 | static HOST_WIDE_INT | |
3156 | get_constant_size (tree exp) | |
3157 | { | |
3158 | HOST_WIDE_INT size; | |
3159 | ||
3160 | size = int_size_in_bytes (TREE_TYPE (exp)); | |
3161 | if (TREE_CODE (exp) == STRING_CST) | |
3162 | size = MAX (TREE_STRING_LENGTH (exp), size); | |
3163 | return size; | |
3164 | } | |
3165 | ||
4f3740f1 | 3166 | /* Subroutine of output_constant_def: |
3167 | No constant equal to EXP is known to have been output. | |
3168 | Make a constant descriptor to enter EXP in the hash table. | |
3169 | Assign the label number and construct RTL to refer to the | |
3170 | constant's location in memory. | |
3171 | Caller is responsible for updating the hash table. */ | |
3172 | ||
3173 | static struct constant_descriptor_tree * | |
3180a54f | 3174 | build_constant_desc (tree exp) |
4f3740f1 | 3175 | { |
3176 | rtx symbol; | |
3177 | rtx rtl; | |
3178 | char label[256]; | |
3179 | int labelno; | |
3180 | struct constant_descriptor_tree *desc; | |
3181 | ||
45ba1503 | 3182 | desc = GGC_NEW (struct constant_descriptor_tree); |
a814bad5 | 3183 | desc->value = copy_constant (exp); |
4f3740f1 | 3184 | |
0bed3869 | 3185 | /* Propagate marked-ness to copied constant. */ |
4ee9c684 | 3186 | if (flag_mudflap && mf_marked_p (exp)) |
3187 | mf_mark (desc->value); | |
3188 | ||
4f3740f1 | 3189 | /* Create a string containing the label name, in LABEL. */ |
3190 | labelno = const_labelno++; | |
3191 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", labelno); | |
3192 | ||
3193 | /* We have a symbol name; construct the SYMBOL_REF and the MEM. */ | |
f2d0e9f1 | 3194 | if (use_object_blocks_p ()) |
3195 | { | |
3196 | section *sect = get_constant_section (exp); | |
3197 | symbol = create_block_symbol (ggc_strdup (label), | |
3198 | get_block_for_section (sect), -1); | |
3199 | } | |
3200 | else | |
3201 | symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)); | |
3202 | SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL; | |
b864739b | 3203 | SET_SYMBOL_REF_DECL (symbol, desc->value); |
658782a5 | 3204 | TREE_CONSTANT_POOL_ADDRESS_P (symbol) = 1; |
4f3740f1 | 3205 | |
3206 | rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), symbol); | |
3207 | set_mem_attributes (rtl, exp, 1); | |
3208 | set_mem_alias_set (rtl, 0); | |
3209 | set_mem_alias_set (rtl, const_alias_set); | |
3210 | ||
3211 | /* Set flags or add text to the name to record information, such as | |
3212 | that it is a local symbol. If the name is changed, the macro | |
3213 | ASM_OUTPUT_LABELREF will have to know how to strip this | |
364bde6b | 3214 | information. This call might invalidate our local variable |
3215 | SYMBOL; we can't use it afterward. */ | |
3216 | ||
883b2e73 | 3217 | targetm.encode_section_info (exp, rtl, true); |
4f3740f1 | 3218 | |
3219 | desc->rtl = rtl; | |
4f3740f1 | 3220 | |
3221 | return desc; | |
3222 | } | |
3223 | ||
5243fbff | 3224 | /* Return an rtx representing a reference to constant data in memory |
3225 | for the constant expression EXP. | |
82e162bb | 3226 | |
5243fbff | 3227 | If assembler code for such a constant has already been output, |
3228 | return an rtx to refer to it. | |
cd1fbf44 | 3229 | Otherwise, output such a constant in memory |
82e162bb | 3230 | and generate an rtx for it. |
3231 | ||
364bde6b | 3232 | If DEFER is nonzero, this constant can be deferred and output only |
3233 | if referenced in the function after all optimizations. | |
abf74c5b | 3234 | |
2e355795 | 3235 | `const_desc_table' records which constants already have label strings. */ |
5243fbff | 3236 | |
3237 | rtx | |
3180a54f | 3238 | output_constant_def (tree exp, int defer) |
5243fbff | 3239 | { |
1f3233d1 | 3240 | struct constant_descriptor_tree *desc; |
364bde6b | 3241 | struct constant_descriptor_tree key; |
3242 | void **loc; | |
5243fbff | 3243 | |
364bde6b | 3244 | /* Look up EXP in the table of constant descriptors. If we didn't find |
3245 | it, create a new one. */ | |
3246 | key.value = exp; | |
a3841d3a | 3247 | key.hash = const_hash_1 (exp); |
3248 | loc = htab_find_slot_with_hash (const_desc_htab, &key, key.hash, INSERT); | |
b7fdac4b | 3249 | |
45ba1503 | 3250 | desc = (struct constant_descriptor_tree *) *loc; |
155b05dc | 3251 | if (desc == 0) |
0671dda2 | 3252 | { |
4f3740f1 | 3253 | desc = build_constant_desc (exp); |
a3841d3a | 3254 | desc->hash = key.hash; |
364bde6b | 3255 | *loc = desc; |
155b05dc | 3256 | } |
3257 | ||
364bde6b | 3258 | maybe_output_constant_def_contents (desc, defer); |
4f3740f1 | 3259 | return desc->rtl; |
3260 | } | |
5243fbff | 3261 | |
364bde6b | 3262 | /* Subroutine of output_constant_def: Decide whether or not we need to |
3263 | output the constant DESC now, and if so, do it. */ | |
4f3740f1 | 3264 | static void |
3180a54f | 3265 | maybe_output_constant_def_contents (struct constant_descriptor_tree *desc, |
3266 | int defer) | |
4f3740f1 | 3267 | { |
364bde6b | 3268 | rtx symbol = XEXP (desc->rtl, 0); |
658782a5 | 3269 | tree exp = desc->value; |
364bde6b | 3270 | |
4f3740f1 | 3271 | if (flag_syntax_only) |
3272 | return; | |
5243fbff | 3273 | |
658782a5 | 3274 | if (TREE_ASM_WRITTEN (exp)) |
364bde6b | 3275 | /* Already output; don't do it again. */ |
3276 | return; | |
3277 | ||
a814bad5 | 3278 | /* We can always defer constants as long as the context allows |
3279 | doing so. */ | |
3280 | if (defer) | |
abf74c5b | 3281 | { |
658782a5 | 3282 | /* Increment n_deferred_constants if it exists. It needs to be at |
3283 | least as large as the number of constants actually referred to | |
3284 | by the function. If it's too small we'll stop looking too early | |
3285 | and fail to emit constants; if it's too large we'll only look | |
3286 | through the entire function when we could have stopped earlier. */ | |
364bde6b | 3287 | if (cfun) |
3288 | n_deferred_constants++; | |
b2fd8d52 | 3289 | return; |
82e162bb | 3290 | } |
3291 | ||
364bde6b | 3292 | output_constant_def_contents (symbol); |
82e162bb | 3293 | } |
3294 | ||
f2d0e9f1 | 3295 | /* Subroutine of output_constant_def_contents. Output the definition |
3296 | of constant EXP, which is pointed to by label LABEL. ALIGN is the | |
3297 | constant's alignment in bits. */ | |
3298 | ||
3299 | static void | |
3300 | assemble_constant_contents (tree exp, const char *label, unsigned int align) | |
3301 | { | |
3302 | HOST_WIDE_INT size; | |
3303 | ||
3304 | size = get_constant_size (exp); | |
3305 | ||
3306 | /* Do any machine/system dependent processing of the constant. */ | |
3307 | #ifdef ASM_DECLARE_CONSTANT_NAME | |
3308 | ASM_DECLARE_CONSTANT_NAME (asm_out_file, label, exp, size); | |
3309 | #else | |
3310 | /* Standard thing is just output label for the constant. */ | |
3311 | ASM_OUTPUT_LABEL (asm_out_file, label); | |
3312 | #endif /* ASM_DECLARE_CONSTANT_NAME */ | |
3313 | ||
3314 | /* Output the value of EXP. */ | |
3315 | output_constant (exp, size, align); | |
3316 | } | |
3317 | ||
364bde6b | 3318 | /* We must output the constant data referred to by SYMBOL; do so. */ |
5243fbff | 3319 | |
82e162bb | 3320 | static void |
3180a54f | 3321 | output_constant_def_contents (rtx symbol) |
82e162bb | 3322 | { |
364bde6b | 3323 | tree exp = SYMBOL_REF_DECL (symbol); |
f2d0e9f1 | 3324 | unsigned int align; |
364bde6b | 3325 | |
4f3740f1 | 3326 | /* Make sure any other constants whose addresses appear in EXP |
3327 | are assigned label numbers. */ | |
ee4722fe | 3328 | output_addressed_constants (exp); |
3329 | ||
364bde6b | 3330 | /* We are no longer deferring this constant. */ |
658782a5 | 3331 | TREE_ASM_WRITTEN (exp) = 1; |
364bde6b | 3332 | |
f2d0e9f1 | 3333 | /* If the constant is part of an object block, make sure that the |
3334 | decl has been positioned within its block, but do not write out | |
3335 | its definition yet. output_object_blocks will do that later. */ | |
6617cbc1 | 3336 | if (SYMBOL_REF_HAS_BLOCK_INFO_P (symbol) && SYMBOL_REF_BLOCK (symbol)) |
f2d0e9f1 | 3337 | place_block_symbol (symbol); |
0b30896b | 3338 | else |
77ec0c64 | 3339 | { |
f2d0e9f1 | 3340 | switch_to_section (get_constant_section (exp)); |
3341 | align = get_constant_alignment (exp); | |
3342 | if (align > BITS_PER_UNIT) | |
3343 | ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT)); | |
3344 | assemble_constant_contents (exp, XSTR (symbol, 0), align); | |
77ec0c64 | 3345 | } |
4ee9c684 | 3346 | if (flag_mudflap) |
3347 | mudflap_enqueue_constant (exp); | |
91b9ca14 | 3348 | } |
6e326506 | 3349 | |
3350 | /* Look up EXP in the table of constant descriptors. Return the rtl | |
3351 | if it has been emitted, else null. */ | |
3352 | ||
3353 | rtx | |
3354 | lookup_constant_def (tree exp) | |
3355 | { | |
3356 | struct constant_descriptor_tree *desc; | |
3357 | struct constant_descriptor_tree key; | |
3358 | ||
3359 | key.value = exp; | |
a3841d3a | 3360 | key.hash = const_hash_1 (exp); |
45ba1503 | 3361 | desc = (struct constant_descriptor_tree *) |
3362 | htab_find_with_hash (const_desc_htab, &key, key.hash); | |
6e326506 | 3363 | |
3364 | return (desc ? desc->rtl : NULL_RTX); | |
3365 | } | |
5243fbff | 3366 | \f |
1f3233d1 | 3367 | /* Used in the hash tables to avoid outputting the same constant |
3368 | twice. Unlike 'struct constant_descriptor_tree', RTX constants | |
01714e38 | 3369 | are output once per function, not once per file. */ |
3370 | /* ??? Only a few targets need per-function constant pools. Most | |
3371 | can use one per-file pool. Should add a targetm bit to tell the | |
3372 | difference. */ | |
3373 | ||
fb1e4f4a | 3374 | struct GTY(()) rtx_constant_pool { |
01714e38 | 3375 | /* Pointers to first and last constant in pool, as ordered by offset. */ |
3376 | struct constant_descriptor_rtx *first; | |
3377 | struct constant_descriptor_rtx *last; | |
3378 | ||
3379 | /* Hash facility for making memory-constants from constant rtl-expressions. | |
3380 | It is used on RISC machines where immediate integer arguments and | |
3381 | constant addresses are restricted so that such constants must be stored | |
3382 | in memory. */ | |
3383 | htab_t GTY((param_is (struct constant_descriptor_rtx))) const_rtx_htab; | |
01714e38 | 3384 | |
3385 | /* Current offset in constant pool (does not include any | |
3386 | machine-specific header). */ | |
3387 | HOST_WIDE_INT offset; | |
1f3233d1 | 3388 | }; |
3389 | ||
fb1e4f4a | 3390 | struct GTY((chain_next ("%h.next"))) constant_descriptor_rtx { |
01714e38 | 3391 | struct constant_descriptor_rtx *next; |
3392 | rtx mem; | |
3393 | rtx sym; | |
5243fbff | 3394 | rtx constant; |
01714e38 | 3395 | HOST_WIDE_INT offset; |
3396 | hashval_t hash; | |
2e04a8ae | 3397 | enum machine_mode mode; |
ebde4c17 | 3398 | unsigned int align; |
01714e38 | 3399 | int labelno; |
1fc4c247 | 3400 | int mark; |
5243fbff | 3401 | }; |
3402 | ||
01714e38 | 3403 | /* Hash and compare functions for const_rtx_htab. */ |
5243fbff | 3404 | |
01714e38 | 3405 | static hashval_t |
3406 | const_desc_rtx_hash (const void *ptr) | |
3407 | { | |
45ba1503 | 3408 | const struct constant_descriptor_rtx *const desc |
3409 | = (const struct constant_descriptor_rtx *) ptr; | |
01714e38 | 3410 | return desc->hash; |
3411 | } | |
5243fbff | 3412 | |
01714e38 | 3413 | static int |
3414 | const_desc_rtx_eq (const void *a, const void *b) | |
5243fbff | 3415 | { |
45ba1503 | 3416 | const struct constant_descriptor_rtx *const x |
3417 | = (const struct constant_descriptor_rtx *) a; | |
3418 | const struct constant_descriptor_rtx *const y | |
3419 | = (const struct constant_descriptor_rtx *) b; | |
01714e38 | 3420 | |
3421 | if (x->mode != y->mode) | |
3422 | return 0; | |
3423 | return rtx_equal_p (x->constant, y->constant); | |
1cc10897 | 3424 | } |
5243fbff | 3425 | |
01714e38 | 3426 | /* This is the worker function for const_rtx_hash, called via for_each_rtx. */ |
3393215f | 3427 | |
01714e38 | 3428 | static int |
3429 | const_rtx_hash_1 (rtx *xp, void *data) | |
3430 | { | |
3431 | unsigned HOST_WIDE_INT hwi; | |
3432 | enum machine_mode mode; | |
3433 | enum rtx_code code; | |
3434 | hashval_t h, *hp; | |
3435 | rtx x; | |
3393215f | 3436 | |
01714e38 | 3437 | x = *xp; |
3438 | code = GET_CODE (x); | |
3439 | mode = GET_MODE (x); | |
3440 | h = (hashval_t) code * 1048573 + mode; | |
5243fbff | 3441 | |
01714e38 | 3442 | switch (code) |
3443 | { | |
3444 | case CONST_INT: | |
3445 | hwi = INTVAL (x); | |
3446 | fold_hwi: | |
886cfd4f | 3447 | { |
8e7b72c4 | 3448 | int shift = sizeof (hashval_t) * CHAR_BIT; |
01714e38 | 3449 | const int n = sizeof (HOST_WIDE_INT) / sizeof (hashval_t); |
3450 | int i; | |
886cfd4f | 3451 | |
01714e38 | 3452 | h ^= (hashval_t) hwi; |
3453 | for (i = 1; i < n; ++i) | |
3393215f | 3454 | { |
01714e38 | 3455 | hwi >>= shift; |
3456 | h ^= (hashval_t) hwi; | |
886cfd4f | 3457 | } |
3458 | } | |
3459 | break; | |
3460 | ||
01714e38 | 3461 | case CONST_DOUBLE: |
3462 | if (mode == VOIDmode) | |
3463 | { | |
3464 | hwi = CONST_DOUBLE_LOW (x) ^ CONST_DOUBLE_HIGH (x); | |
3465 | goto fold_hwi; | |
3466 | } | |
3467 | else | |
3468 | h ^= real_hash (CONST_DOUBLE_REAL_VALUE (x)); | |
5243fbff | 3469 | break; |
3470 | ||
e397ad8e | 3471 | case CONST_FIXED: |
3472 | h ^= fixed_hash (CONST_FIXED_VALUE (x)); | |
3473 | break; | |
3474 | ||
d2be3003 | 3475 | case CONST_VECTOR: |
3476 | { | |
3477 | int i; | |
3478 | for (i = XVECLEN (x, 0); i-- > 0; ) | |
3479 | h = h * 251 + const_rtx_hash_1 (&XVECEXP (x, 0, i), data); | |
3480 | } | |
3481 | break; | |
3482 | ||
5243fbff | 3483 | case SYMBOL_REF: |
01714e38 | 3484 | h ^= htab_hash_string (XSTR (x, 0)); |
3485 | break; | |
3486 | ||
5243fbff | 3487 | case LABEL_REF: |
01714e38 | 3488 | h = h * 251 + CODE_LABEL_NUMBER (XEXP (x, 0)); |
5243fbff | 3489 | break; |
3490 | ||
01714e38 | 3491 | case UNSPEC: |
3492 | case UNSPEC_VOLATILE: | |
3493 | h = h * 251 + XINT (x, 1); | |
5243fbff | 3494 | break; |
3495 | ||
3496 | default: | |
5b1bb114 | 3497 | break; |
5243fbff | 3498 | } |
3499 | ||
45ba1503 | 3500 | hp = (hashval_t *) data; |
01714e38 | 3501 | *hp = *hp * 509 + h; |
3502 | return 0; | |
5243fbff | 3503 | } |
3504 | ||
01714e38 | 3505 | /* Compute a hash value for X, which should be a constant. */ |
1cc10897 | 3506 | |
01714e38 | 3507 | static hashval_t |
3508 | const_rtx_hash (rtx x) | |
1cc10897 | 3509 | { |
01714e38 | 3510 | hashval_t h = 0; |
3511 | for_each_rtx (&x, const_rtx_hash_1, &h); | |
3512 | return h; | |
1cc10897 | 3513 | } |
3514 | ||
01714e38 | 3515 | \f |
2dbdc48e | 3516 | /* Create and return a new rtx constant pool. */ |
3517 | ||
3518 | static struct rtx_constant_pool * | |
3519 | create_constant_pool (void) | |
3520 | { | |
3521 | struct rtx_constant_pool *pool; | |
3522 | ||
45ba1503 | 3523 | pool = GGC_NEW (struct rtx_constant_pool); |
2dbdc48e | 3524 | pool->const_rtx_htab = htab_create_ggc (31, const_desc_rtx_hash, |
3525 | const_desc_rtx_eq, NULL); | |
3526 | pool->first = NULL; | |
3527 | pool->last = NULL; | |
3528 | pool->offset = 0; | |
3529 | return pool; | |
3530 | } | |
3531 | ||
01714e38 | 3532 | /* Initialize constant pool hashing for a new function. */ |
5243fbff | 3533 | |
01714e38 | 3534 | void |
b079a207 | 3535 | init_varasm_status (void) |
5243fbff | 3536 | { |
fd6ffb7c | 3537 | crtl->varasm.pool = create_constant_pool (); |
3538 | crtl->varasm.deferred_constants = 0; | |
5243fbff | 3539 | } |
01714e38 | 3540 | \f |
3541 | /* Given a MINUS expression, simplify it if both sides | |
3542 | include the same symbol. */ | |
5243fbff | 3543 | |
01714e38 | 3544 | rtx |
3545 | simplify_subtraction (rtx x) | |
5243fbff | 3546 | { |
01714e38 | 3547 | rtx r = simplify_rtx (x); |
3548 | return r ? r : x; | |
5243fbff | 3549 | } |
3550 | \f | |
3551 | /* Given a constant rtx X, make (or find) a memory constant for its value | |
3552 | and return a MEM rtx to refer to it in memory. */ | |
3553 | ||
3554 | rtx | |
3180a54f | 3555 | force_const_mem (enum machine_mode mode, rtx x) |
5243fbff | 3556 | { |
01714e38 | 3557 | struct constant_descriptor_rtx *desc, tmp; |
2dbdc48e | 3558 | struct rtx_constant_pool *pool; |
5243fbff | 3559 | char label[256]; |
001be062 | 3560 | rtx def, symbol; |
01714e38 | 3561 | hashval_t hash; |
ebde4c17 | 3562 | unsigned int align; |
01714e38 | 3563 | void **slot; |
5243fbff | 3564 | |
a6bbccc1 | 3565 | /* If we're not allowed to drop X into the constant pool, don't. */ |
883b2e73 | 3566 | if (targetm.cannot_force_const_mem (x)) |
a6bbccc1 | 3567 | return NULL_RTX; |
3568 | ||
2dbdc48e | 3569 | /* Record that this function has used a constant pool entry. */ |
18d50ae6 | 3570 | crtl->uses_const_pool = 1; |
2dbdc48e | 3571 | |
3572 | /* Decide which pool to use. */ | |
3573 | pool = (targetm.use_blocks_for_constant_p (mode, x) | |
3574 | ? shared_constant_pool | |
fd6ffb7c | 3575 | : crtl->varasm.pool); |
2dbdc48e | 3576 | |
01714e38 | 3577 | /* Lookup the value in the hashtable. */ |
3578 | tmp.constant = x; | |
3579 | tmp.mode = mode; | |
3580 | hash = const_rtx_hash (x); | |
3581 | slot = htab_find_slot_with_hash (pool->const_rtx_htab, &tmp, hash, INSERT); | |
45ba1503 | 3582 | desc = (struct constant_descriptor_rtx *) *slot; |
b215c058 | 3583 | |
01714e38 | 3584 | /* If the constant was already present, return its memory. */ |
3585 | if (desc) | |
3586 | return copy_rtx (desc->mem); | |
3587 | ||
3588 | /* Otherwise, create a new descriptor. */ | |
45ba1503 | 3589 | desc = GGC_NEW (struct constant_descriptor_rtx); |
01714e38 | 3590 | *slot = desc; |
bc70bd5e | 3591 | |
ebde4c17 | 3592 | /* Align the location counter as required by EXP's data type. */ |
3593 | align = GET_MODE_ALIGNMENT (mode == VOIDmode ? word_mode : mode); | |
f7d6703c | 3594 | #ifdef CONSTANT_ALIGNMENT |
5e8603b7 | 3595 | { |
dc24ddbd | 3596 | tree type = lang_hooks.types.type_for_mode (mode, 0); |
5e8603b7 | 3597 | if (type != NULL_TREE) |
3598 | align = CONSTANT_ALIGNMENT (make_tree (type, x), align); | |
3599 | } | |
f7d6703c | 3600 | #endif |
5243fbff | 3601 | |
01714e38 | 3602 | pool->offset += (align / BITS_PER_UNIT) - 1; |
3603 | pool->offset &= ~ ((align / BITS_PER_UNIT) - 1); | |
3604 | ||
3605 | desc->next = NULL; | |
3606 | desc->constant = tmp.constant; | |
3607 | desc->offset = pool->offset; | |
3608 | desc->hash = hash; | |
3609 | desc->mode = mode; | |
3610 | desc->align = align; | |
3611 | desc->labelno = const_labelno; | |
3612 | desc->mark = 0; | |
3613 | ||
3614 | pool->offset += GET_MODE_SIZE (mode); | |
3615 | if (pool->last) | |
3616 | pool->last->next = desc; | |
ebde4c17 | 3617 | else |
01714e38 | 3618 | pool->first = pool->last = desc; |
3619 | pool->last = desc; | |
5243fbff | 3620 | |
ebde4c17 | 3621 | /* Create a string containing the label name, in LABEL. */ |
3622 | ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); | |
ebde4c17 | 3623 | ++const_labelno; |
5243fbff | 3624 | |
01714e38 | 3625 | /* Construct the SYMBOL_REF. Make sure to mark it as belonging to |
3626 | the constants pool. */ | |
f2d0e9f1 | 3627 | if (use_object_blocks_p () && targetm.use_blocks_for_constant_p (mode, x)) |
3628 | { | |
3629 | section *sect = targetm.asm_out.select_rtx_section (mode, x, align); | |
3630 | symbol = create_block_symbol (ggc_strdup (label), | |
3631 | get_block_for_section (sect), -1); | |
3632 | } | |
3633 | else | |
3634 | symbol = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (label)); | |
3635 | desc->sym = symbol; | |
3636 | SYMBOL_REF_FLAGS (symbol) |= SYMBOL_FLAG_LOCAL; | |
01714e38 | 3637 | CONSTANT_POOL_ADDRESS_P (symbol) = 1; |
b864739b | 3638 | SET_SYMBOL_REF_CONSTANT (symbol, desc); |
01714e38 | 3639 | |
01714e38 | 3640 | /* Construct the MEM. */ |
e265a6da | 3641 | desc->mem = def = gen_const_mem (mode, symbol); |
dc24ddbd | 3642 | set_mem_attributes (def, lang_hooks.types.type_for_mode (mode, 0), 1); |
8c34e451 | 3643 | set_mem_align (def, align); |
7f761dda | 3644 | |
01714e38 | 3645 | /* If we're dropping a label to the constant pool, make sure we |
3646 | don't delete it. */ | |
3647 | if (GET_CODE (x) == LABEL_REF) | |
3648 | LABEL_PRESERVE_P (XEXP (x, 0)) = 1; | |
5243fbff | 3649 | |
3f26eaa9 | 3650 | return copy_rtx (def); |
5243fbff | 3651 | } |
3652 | \f | |
5243fbff | 3653 | /* Given a constant pool SYMBOL_REF, return the corresponding constant. */ |
3654 | ||
3655 | rtx | |
3180a54f | 3656 | get_pool_constant (rtx addr) |
5243fbff | 3657 | { |
7c266bb1 | 3658 | return SYMBOL_REF_CONSTANT (addr)->constant; |
605f66ec | 3659 | } |
3660 | ||
7ad1c520 | 3661 | /* Given a constant pool SYMBOL_REF, return the corresponding constant |
3662 | and whether it has been output or not. */ | |
3663 | ||
3664 | rtx | |
3180a54f | 3665 | get_pool_constant_mark (rtx addr, bool *pmarked) |
7ad1c520 | 3666 | { |
01714e38 | 3667 | struct constant_descriptor_rtx *desc; |
3668 | ||
7c266bb1 | 3669 | desc = SYMBOL_REF_CONSTANT (addr); |
01714e38 | 3670 | *pmarked = (desc->mark != 0); |
3671 | return desc->constant; | |
7ad1c520 | 3672 | } |
3673 | ||
5243fbff | 3674 | /* Similar, return the mode. */ |
3675 | ||
3676 | enum machine_mode | |
dd9b9fc5 | 3677 | get_pool_mode (const_rtx addr) |
5243fbff | 3678 | { |
7c266bb1 | 3679 | return SYMBOL_REF_CONSTANT (addr)->mode; |
605f66ec | 3680 | } |
3681 | ||
5243fbff | 3682 | /* Return the size of the constant pool. */ |
3683 | ||
3684 | int | |
3180a54f | 3685 | get_pool_size (void) |
5243fbff | 3686 | { |
fd6ffb7c | 3687 | return crtl->varasm.pool->offset; |
5243fbff | 3688 | } |
3689 | \f | |
01714e38 | 3690 | /* Worker function for output_constant_pool_1. Emit assembly for X |
3691 | in MODE with known alignment ALIGN. */ | |
5243fbff | 3692 | |
01714e38 | 3693 | static void |
3694 | output_constant_pool_2 (enum machine_mode mode, rtx x, unsigned int align) | |
5243fbff | 3695 | { |
01714e38 | 3696 | switch (GET_MODE_CLASS (mode)) |
5243fbff | 3697 | { |
01714e38 | 3698 | case MODE_FLOAT: |
069b07bf | 3699 | case MODE_DECIMAL_FLOAT: |
22167fd5 | 3700 | { |
3701 | REAL_VALUE_TYPE r; | |
b215c058 | 3702 | |
22167fd5 | 3703 | gcc_assert (GET_CODE (x) == CONST_DOUBLE); |
3704 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
3705 | assemble_real (r, mode, align); | |
3706 | break; | |
3707 | } | |
b215c058 | 3708 | |
01714e38 | 3709 | case MODE_INT: |
3710 | case MODE_PARTIAL_INT: | |
e397ad8e | 3711 | case MODE_FRACT: |
3712 | case MODE_UFRACT: | |
3713 | case MODE_ACCUM: | |
3714 | case MODE_UACCUM: | |
01714e38 | 3715 | assemble_integer (x, GET_MODE_SIZE (mode), align, 1); |
3716 | break; | |
5243fbff | 3717 | |
01714e38 | 3718 | case MODE_VECTOR_FLOAT: |
3719 | case MODE_VECTOR_INT: | |
e397ad8e | 3720 | case MODE_VECTOR_FRACT: |
3721 | case MODE_VECTOR_UFRACT: | |
3722 | case MODE_VECTOR_ACCUM: | |
3723 | case MODE_VECTOR_UACCUM: | |
01714e38 | 3724 | { |
3725 | int i, units; | |
3726 | enum machine_mode submode = GET_MODE_INNER (mode); | |
3727 | unsigned int subalign = MIN (align, GET_MODE_BITSIZE (submode)); | |
5243fbff | 3728 | |
22167fd5 | 3729 | gcc_assert (GET_CODE (x) == CONST_VECTOR); |
01714e38 | 3730 | units = CONST_VECTOR_NUNITS (x); |
5243fbff | 3731 | |
01714e38 | 3732 | for (i = 0; i < units; i++) |
886cfd4f | 3733 | { |
01714e38 | 3734 | rtx elt = CONST_VECTOR_ELT (x, i); |
3735 | output_constant_pool_2 (submode, elt, i ? subalign : align); | |
886cfd4f | 3736 | } |
01714e38 | 3737 | } |
3738 | break; | |
886cfd4f | 3739 | |
01714e38 | 3740 | default: |
22167fd5 | 3741 | gcc_unreachable (); |
01714e38 | 3742 | } |
3743 | } | |
886cfd4f | 3744 | |
f2d0e9f1 | 3745 | /* Worker function for output_constant_pool. Emit constant DESC, |
3746 | giving it ALIGN bits of alignment. */ | |
886cfd4f | 3747 | |
01714e38 | 3748 | static void |
f2d0e9f1 | 3749 | output_constant_pool_1 (struct constant_descriptor_rtx *desc, |
3750 | unsigned int align) | |
01714e38 | 3751 | { |
3752 | rtx x, tmp; | |
886cfd4f | 3753 | |
01714e38 | 3754 | x = desc->constant; |
3755 | ||
3756 | /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF) | |
3757 | whose CODE_LABEL has been deleted. This can occur if a jump table | |
3758 | is eliminated by optimization. If so, write a constant of zero | |
3759 | instead. Note that this can also happen by turning the | |
3760 | CODE_LABEL into a NOTE. */ | |
3761 | /* ??? This seems completely and utterly wrong. Certainly it's | |
3762 | not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper | |
3763 | functioning even with INSN_DELETED_P and friends. */ | |
3764 | ||
3765 | tmp = x; | |
4bd8d9a1 | 3766 | switch (GET_CODE (tmp)) |
01714e38 | 3767 | { |
3768 | case CONST: | |
4bd8d9a1 | 3769 | if (GET_CODE (XEXP (tmp, 0)) != PLUS |
3770 | || GET_CODE (XEXP (XEXP (tmp, 0), 0)) != LABEL_REF) | |
01714e38 | 3771 | break; |
4bd8d9a1 | 3772 | tmp = XEXP (XEXP (tmp, 0), 0); |
01714e38 | 3773 | /* FALLTHRU */ |
886cfd4f | 3774 | |
01714e38 | 3775 | case LABEL_REF: |
4bd8d9a1 | 3776 | tmp = XEXP (tmp, 0); |
22167fd5 | 3777 | gcc_assert (!INSN_DELETED_P (tmp)); |
3778 | gcc_assert (!NOTE_P (tmp) | |
ad4583d9 | 3779 | || NOTE_KIND (tmp) != NOTE_INSN_DELETED); |
01714e38 | 3780 | break; |
5243fbff | 3781 | |
01714e38 | 3782 | default: |
3783 | break; | |
3784 | } | |
3785 | ||
7bd36830 | 3786 | #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY |
01714e38 | 3787 | ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, desc->mode, |
f2d0e9f1 | 3788 | align, desc->labelno, done); |
7bd36830 | 3789 | #endif |
697d72bb | 3790 | |
f2d0e9f1 | 3791 | assemble_align (align); |
7b4ca927 | 3792 | |
01714e38 | 3793 | /* Output the label. */ |
883b2e73 | 3794 | targetm.asm_out.internal_label (asm_out_file, "LC", desc->labelno); |
1fc4c247 | 3795 | |
01714e38 | 3796 | /* Output the data. */ |
f2d0e9f1 | 3797 | output_constant_pool_2 (desc->mode, x, align); |
1fc4c247 | 3798 | |
01714e38 | 3799 | /* Make sure all constants in SECTION_MERGE and not SECTION_STRINGS |
3800 | sections have proper size. */ | |
f2d0e9f1 | 3801 | if (align > GET_MODE_BITSIZE (desc->mode) |
2f14b1f9 | 3802 | && in_section |
3803 | && (in_section->common.flags & SECTION_MERGE)) | |
f2d0e9f1 | 3804 | assemble_align (align); |
1fc4c247 | 3805 | |
01714e38 | 3806 | #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY |
3807 | done: | |
3808 | #endif | |
3809 | return; | |
3810 | } | |
1fc4c247 | 3811 | |
01714e38 | 3812 | /* Given a SYMBOL_REF CURRENT_RTX, mark it and all constants it refers |
3813 | to as used. Emit referenced deferred strings. This function can | |
3814 | be used with for_each_rtx to mark all SYMBOL_REFs in an rtx. */ | |
29021bde | 3815 | |
01714e38 | 3816 | static int |
2dbdc48e | 3817 | mark_constant (rtx *current_rtx, void *data ATTRIBUTE_UNUSED) |
01714e38 | 3818 | { |
01714e38 | 3819 | rtx x = *current_rtx; |
1fc4c247 | 3820 | |
01714e38 | 3821 | if (x == NULL_RTX || GET_CODE (x) != SYMBOL_REF) |
3822 | return 0; | |
478e3127 | 3823 | |
01714e38 | 3824 | if (CONSTANT_POOL_ADDRESS_P (x)) |
3825 | { | |
7c266bb1 | 3826 | struct constant_descriptor_rtx *desc = SYMBOL_REF_CONSTANT (x); |
01714e38 | 3827 | if (desc->mark == 0) |
3828 | { | |
3829 | desc->mark = 1; | |
2dbdc48e | 3830 | for_each_rtx (&desc->constant, mark_constant, NULL); |
01714e38 | 3831 | } |
478e3127 | 3832 | } |
01714e38 | 3833 | else if (TREE_CONSTANT_POOL_ADDRESS_P (x)) |
3834 | { | |
3835 | tree exp = SYMBOL_REF_DECL (x); | |
3836 | if (!TREE_ASM_WRITTEN (exp)) | |
3837 | { | |
3838 | n_deferred_constants--; | |
3839 | output_constant_def_contents (x); | |
3840 | } | |
3841 | } | |
3842 | ||
3843 | return -1; | |
b215c058 | 3844 | } |
1fc4c247 | 3845 | |
01714e38 | 3846 | /* Look through appropriate parts of INSN, marking all entries in the |
af295e6f | 3847 | constant pool which are actually being used. Entries that are only |
3848 | referenced by other constants are also marked as used. Emit | |
3849 | deferred strings that are used. */ | |
3850 | ||
1fc4c247 | 3851 | static void |
2dbdc48e | 3852 | mark_constants (rtx insn) |
1fc4c247 | 3853 | { |
01714e38 | 3854 | if (!INSN_P (insn)) |
1fc4c247 | 3855 | return; |
3856 | ||
1fc4c247 | 3857 | /* Insns may appear inside a SEQUENCE. Only check the patterns of |
3858 | insns, not any notes that may be attached. We don't want to mark | |
3859 | a constant just because it happens to appear in a REG_EQUIV note. */ | |
01714e38 | 3860 | if (GET_CODE (PATTERN (insn)) == SEQUENCE) |
1fc4c247 | 3861 | { |
01714e38 | 3862 | rtx seq = PATTERN (insn); |
3863 | int i, n = XVECLEN (seq, 0); | |
3864 | for (i = 0; i < n; ++i) | |
3865 | { | |
3866 | rtx subinsn = XVECEXP (seq, 0, i); | |
3867 | if (INSN_P (subinsn)) | |
2dbdc48e | 3868 | for_each_rtx (&PATTERN (subinsn), mark_constant, NULL); |
01714e38 | 3869 | } |
1fc4c247 | 3870 | } |
01714e38 | 3871 | else |
2dbdc48e | 3872 | for_each_rtx (&PATTERN (insn), mark_constant, NULL); |
01714e38 | 3873 | } |
1fc4c247 | 3874 | |
01714e38 | 3875 | /* Look through the instructions for this function, and mark all the |
3876 | entries in POOL which are actually being used. Emit deferred constants | |
3877 | which have indeed been used. */ | |
1fc4c247 | 3878 | |
01714e38 | 3879 | static void |
2dbdc48e | 3880 | mark_constant_pool (void) |
01714e38 | 3881 | { |
3882 | rtx insn, link; | |
1fc4c247 | 3883 | |
18d50ae6 | 3884 | if (!crtl->uses_const_pool && n_deferred_constants == 0) |
01714e38 | 3885 | return; |
1fc4c247 | 3886 | |
01714e38 | 3887 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) |
2dbdc48e | 3888 | mark_constants (insn); |
1fc4c247 | 3889 | |
edb7afe8 | 3890 | for (link = crtl->epilogue_delay_list; |
01714e38 | 3891 | link; |
3892 | link = XEXP (link, 1)) | |
2dbdc48e | 3893 | mark_constants (XEXP (link, 0)); |
1fc4c247 | 3894 | } |
af295e6f | 3895 | |
2dbdc48e | 3896 | /* Write all the constants in POOL. */ |
af295e6f | 3897 | |
2dbdc48e | 3898 | static void |
3899 | output_constant_pool_contents (struct rtx_constant_pool *pool) | |
af295e6f | 3900 | { |
01714e38 | 3901 | struct constant_descriptor_rtx *desc; |
af295e6f | 3902 | |
01714e38 | 3903 | for (desc = pool->first; desc ; desc = desc->next) |
f2d0e9f1 | 3904 | if (desc->mark) |
3905 | { | |
3906 | /* If the constant is part of an object_block, make sure that | |
3907 | the constant has been positioned within its block, but do not | |
3908 | write out its definition yet. output_object_blocks will do | |
3909 | that later. */ | |
6617cbc1 | 3910 | if (SYMBOL_REF_HAS_BLOCK_INFO_P (desc->sym) |
3911 | && SYMBOL_REF_BLOCK (desc->sym)) | |
f2d0e9f1 | 3912 | place_block_symbol (desc->sym); |
3913 | else | |
3914 | { | |
3915 | switch_to_section (targetm.asm_out.select_rtx_section | |
3916 | (desc->mode, desc->constant, desc->align)); | |
3917 | output_constant_pool_1 (desc, desc->align); | |
3918 | } | |
3919 | } | |
2dbdc48e | 3920 | } |
3921 | ||
3922 | /* Mark all constants that are used in the current function, then write | |
3923 | out the function's private constant pool. */ | |
3924 | ||
3925 | static void | |
372df111 | 3926 | output_constant_pool (const char *fnname ATTRIBUTE_UNUSED, |
3927 | tree fndecl ATTRIBUTE_UNUSED) | |
2dbdc48e | 3928 | { |
fd6ffb7c | 3929 | struct rtx_constant_pool *pool = crtl->varasm.pool; |
2dbdc48e | 3930 | |
3931 | /* It is possible for gcc to call force_const_mem and then to later | |
3932 | discard the instructions which refer to the constant. In such a | |
3933 | case we do not need to output the constant. */ | |
3934 | mark_constant_pool (); | |
3935 | ||
3936 | #ifdef ASM_OUTPUT_POOL_PROLOGUE | |
3937 | ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool->offset); | |
3938 | #endif | |
3939 | ||
3940 | output_constant_pool_contents (pool); | |
01714e38 | 3941 | |
3942 | #ifdef ASM_OUTPUT_POOL_EPILOGUE | |
3943 | ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool->offset); | |
3944 | #endif | |
af295e6f | 3945 | } |
5243fbff | 3946 | \f |
2dbdc48e | 3947 | /* Write the contents of the shared constant pool. */ |
3948 | ||
3949 | void | |
3950 | output_shared_constant_pool (void) | |
3951 | { | |
3952 | output_constant_pool_contents (shared_constant_pool); | |
3953 | } | |
3954 | \f | |
ee4722fe | 3955 | /* Determine what kind of relocations EXP may need. */ |
5243fbff | 3956 | |
ee4722fe | 3957 | int |
3958 | compute_reloc_for_constant (tree exp) | |
5243fbff | 3959 | { |
98a1d439 | 3960 | int reloc = 0, reloc2; |
b3187c7c | 3961 | tree tem; |
5243fbff | 3962 | |
3963 | switch (TREE_CODE (exp)) | |
3964 | { | |
3965 | case ADDR_EXPR: | |
feb489ec | 3966 | case FDESC_EXPR: |
b3187c7c | 3967 | /* Go inside any operations that get_inner_reference can handle and see |
3968 | if what's inside is a constant: no need to do anything here for | |
3969 | addresses of variables or functions. */ | |
3970 | for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem); | |
3971 | tem = TREE_OPERAND (tem, 0)) | |
3972 | ; | |
5243fbff | 3973 | |
3087f4a7 | 3974 | if (TREE_PUBLIC (tem)) |
3975 | reloc |= 2; | |
3976 | else | |
3977 | reloc |= 1; | |
5243fbff | 3978 | break; |
3979 | ||
3980 | case PLUS_EXPR: | |
0de36bdb | 3981 | case POINTER_PLUS_EXPR: |
ee4722fe | 3982 | reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0)); |
3983 | reloc |= compute_reloc_for_constant (TREE_OPERAND (exp, 1)); | |
5243fbff | 3984 | break; |
3985 | ||
98a1d439 | 3986 | case MINUS_EXPR: |
ee4722fe | 3987 | reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0)); |
3988 | reloc2 = compute_reloc_for_constant (TREE_OPERAND (exp, 1)); | |
98a1d439 | 3989 | /* The difference of two local labels is computable at link time. */ |
3990 | if (reloc == 1 && reloc2 == 1) | |
3991 | reloc = 0; | |
3992 | else | |
3993 | reloc |= reloc2; | |
3994 | break; | |
3995 | ||
72dd6141 | 3996 | CASE_CONVERT: |
cb96494f | 3997 | case VIEW_CONVERT_EXPR: |
ee4722fe | 3998 | reloc = compute_reloc_for_constant (TREE_OPERAND (exp, 0)); |
5243fbff | 3999 | break; |
4000 | ||
4001 | case CONSTRUCTOR: | |
c75b4594 | 4002 | { |
4003 | unsigned HOST_WIDE_INT idx; | |
4004 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem) | |
4005 | if (tem != 0) | |
4006 | reloc |= compute_reloc_for_constant (tem); | |
4007 | } | |
5243fbff | 4008 | break; |
4009 | ||
0dbd1c74 | 4010 | default: |
5243fbff | 4011 | break; |
4012 | } | |
4013 | return reloc; | |
4014 | } | |
ee4722fe | 4015 | |
4016 | /* Find all the constants whose addresses are referenced inside of EXP, | |
4017 | and make sure assembler code with a label has been output for each one. | |
4018 | Indicate whether an ADDR_EXPR has been encountered. */ | |
4019 | ||
4020 | static void | |
4021 | output_addressed_constants (tree exp) | |
4022 | { | |
4023 | tree tem; | |
4024 | ||
ee4722fe | 4025 | switch (TREE_CODE (exp)) |
4026 | { | |
4027 | case ADDR_EXPR: | |
4028 | case FDESC_EXPR: | |
4029 | /* Go inside any operations that get_inner_reference can handle and see | |
4030 | if what's inside is a constant: no need to do anything here for | |
4031 | addresses of variables or functions. */ | |
4032 | for (tem = TREE_OPERAND (exp, 0); handled_component_p (tem); | |
4033 | tem = TREE_OPERAND (tem, 0)) | |
4034 | ; | |
4035 | ||
5dea8689 | 4036 | /* If we have an initialized CONST_DECL, retrieve the initializer. */ |
4037 | if (TREE_CODE (tem) == CONST_DECL && DECL_INITIAL (tem)) | |
4038 | tem = DECL_INITIAL (tem); | |
4039 | ||
ce45a448 | 4040 | if (CONSTANT_CLASS_P (tem) || TREE_CODE (tem) == CONSTRUCTOR) |
ee4722fe | 4041 | output_constant_def (tem, 0); |
4042 | break; | |
4043 | ||
4044 | case PLUS_EXPR: | |
0de36bdb | 4045 | case POINTER_PLUS_EXPR: |
ee4722fe | 4046 | case MINUS_EXPR: |
4047 | output_addressed_constants (TREE_OPERAND (exp, 1)); | |
4048 | /* Fall through. */ | |
4049 | ||
72dd6141 | 4050 | CASE_CONVERT: |
cb96494f | 4051 | case VIEW_CONVERT_EXPR: |
ee4722fe | 4052 | output_addressed_constants (TREE_OPERAND (exp, 0)); |
4053 | break; | |
4054 | ||
4055 | case CONSTRUCTOR: | |
c75b4594 | 4056 | { |
4057 | unsigned HOST_WIDE_INT idx; | |
4058 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, tem) | |
4059 | if (tem != 0) | |
4060 | output_addressed_constants (tem); | |
4061 | } | |
ee4722fe | 4062 | break; |
4063 | ||
4064 | default: | |
4065 | break; | |
4066 | } | |
4067 | } | |
5243fbff | 4068 | \f |
20169a64 | 4069 | /* Whether a constructor CTOR is a valid static constant initializer if all |
4070 | its elements are. This used to be internal to initializer_constant_valid_p | |
4071 | and has been exposed to let other functions like categorize_ctor_elements | |
4072 | evaluate the property while walking a constructor for other purposes. */ | |
4073 | ||
4074 | bool | |
b7bf20db | 4075 | constructor_static_from_elts_p (const_tree ctor) |
20169a64 | 4076 | { |
4077 | return (TREE_CONSTANT (ctor) | |
4078 | && (TREE_CODE (TREE_TYPE (ctor)) == UNION_TYPE | |
4079 | || TREE_CODE (TREE_TYPE (ctor)) == RECORD_TYPE) | |
4080 | && !VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor))); | |
4081 | } | |
4082 | ||
a9d778f8 | 4083 | /* A subroutine of initializer_constant_valid_p. VALUE is a MINUS_EXPR, |
4084 | PLUS_EXPR or POINTER_PLUS_EXPR. This looks for cases of VALUE | |
bd30efc4 | 4085 | which are valid when ENDTYPE is an integer of any size; in |
4086 | particular, this does not accept a pointer minus a constant. This | |
4087 | returns null_pointer_node if the VALUE is an absolute constant | |
2d0e6843 | 4088 | which can be used to initialize a static variable. Otherwise it |
4089 | returns NULL. */ | |
4090 | ||
4091 | static tree | |
4092 | narrowing_initializer_constant_valid_p (tree value, tree endtype) | |
4093 | { | |
4094 | tree op0, op1; | |
4095 | ||
bd30efc4 | 4096 | if (!INTEGRAL_TYPE_P (endtype)) |
4097 | return NULL_TREE; | |
4098 | ||
2d0e6843 | 4099 | op0 = TREE_OPERAND (value, 0); |
4100 | op1 = TREE_OPERAND (value, 1); | |
4101 | ||
4102 | /* Like STRIP_NOPS except allow the operand mode to widen. This | |
4103 | works around a feature of fold that simplifies (int)(p1 - p2) to | |
4104 | ((int)p1 - (int)p2) under the theory that the narrower operation | |
4105 | is cheaper. */ | |
4106 | ||
4107 | while (CONVERT_EXPR_P (op0) | |
4108 | || TREE_CODE (op0) == NON_LVALUE_EXPR) | |
4109 | { | |
4110 | tree inner = TREE_OPERAND (op0, 0); | |
4111 | if (inner == error_mark_node | |
4112 | || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) | |
4113 | || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0))) | |
4114 | > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner))))) | |
4115 | break; | |
4116 | op0 = inner; | |
4117 | } | |
4118 | ||
4119 | while (CONVERT_EXPR_P (op1) | |
4120 | || TREE_CODE (op1) == NON_LVALUE_EXPR) | |
4121 | { | |
4122 | tree inner = TREE_OPERAND (op1, 0); | |
4123 | if (inner == error_mark_node | |
4124 | || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) | |
4125 | || (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op1))) | |
4126 | > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (inner))))) | |
4127 | break; | |
4128 | op1 = inner; | |
4129 | } | |
4130 | ||
4131 | op0 = initializer_constant_valid_p (op0, endtype); | |
4132 | op1 = initializer_constant_valid_p (op1, endtype); | |
4133 | ||
4134 | /* Both initializers must be known. */ | |
4135 | if (op0 && op1) | |
4136 | { | |
a9d778f8 | 4137 | if (op0 == op1 |
4138 | && (op0 == null_pointer_node | |
4139 | || TREE_CODE (value) == MINUS_EXPR)) | |
2d0e6843 | 4140 | return null_pointer_node; |
4141 | ||
4142 | /* Support differences between labels. */ | |
4143 | if (TREE_CODE (op0) == LABEL_DECL | |
4144 | && TREE_CODE (op1) == LABEL_DECL) | |
4145 | return null_pointer_node; | |
4146 | ||
4147 | if (TREE_CODE (op0) == STRING_CST | |
4148 | && TREE_CODE (op1) == STRING_CST | |
4149 | && operand_equal_p (op0, op1, 1)) | |
4150 | return null_pointer_node; | |
4151 | } | |
4152 | ||
4153 | return NULL_TREE; | |
4154 | } | |
4155 | ||
155b05dc | 4156 | /* Return nonzero if VALUE is a valid constant-valued expression |
4157 | for use in initializing a static variable; one that can be an | |
4158 | element of a "constant" initializer. | |
4159 | ||
4160 | Return null_pointer_node if the value is absolute; | |
4161 | if it is relocatable, return the variable that determines the relocation. | |
4162 | We assume that VALUE has been folded as much as possible; | |
4163 | therefore, we do not need to check for such things as | |
4164 | arithmetic-combinations of integers. */ | |
4165 | ||
4166 | tree | |
3180a54f | 4167 | initializer_constant_valid_p (tree value, tree endtype) |
155b05dc | 4168 | { |
2d0e6843 | 4169 | tree ret; |
4170 | ||
155b05dc | 4171 | switch (TREE_CODE (value)) |
4172 | { | |
4173 | case CONSTRUCTOR: | |
20169a64 | 4174 | if (constructor_static_from_elts_p (value)) |
267d45d9 | 4175 | { |
c75b4594 | 4176 | unsigned HOST_WIDE_INT idx; |
267d45d9 | 4177 | tree elt; |
4178 | bool absolute = true; | |
4179 | ||
c75b4594 | 4180 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt) |
267d45d9 | 4181 | { |
4182 | tree reloc; | |
c75b4594 | 4183 | reloc = initializer_constant_valid_p (elt, TREE_TYPE (elt)); |
267d45d9 | 4184 | if (!reloc) |
4185 | return NULL_TREE; | |
4186 | if (reloc != null_pointer_node) | |
4187 | absolute = false; | |
4188 | } | |
4189 | /* For a non-absolute relocation, there is no single | |
4190 | variable that can be "the variable that determines the | |
4191 | relocation." */ | |
4192 | return absolute ? null_pointer_node : error_mark_node; | |
4193 | } | |
b7fdac4b | 4194 | |
267d45d9 | 4195 | return TREE_STATIC (value) ? null_pointer_node : NULL_TREE; |
155b05dc | 4196 | |
4197 | case INTEGER_CST: | |
886cfd4f | 4198 | case VECTOR_CST: |
155b05dc | 4199 | case REAL_CST: |
e397ad8e | 4200 | case FIXED_CST: |
155b05dc | 4201 | case STRING_CST: |
4202 | case COMPLEX_CST: | |
4203 | return null_pointer_node; | |
4204 | ||
4205 | case ADDR_EXPR: | |
6bfa2cc1 | 4206 | case FDESC_EXPR: |
939e9bf1 | 4207 | { |
4208 | tree op0 = staticp (TREE_OPERAND (value, 0)); | |
4209 | if (op0) | |
4210 | { | |
4211 | /* "&(*a).f" is like unto pointer arithmetic. If "a" turns out | |
4212 | to be a constant, this is old-skool offsetof-like nonsense. */ | |
4213 | if (TREE_CODE (op0) == INDIRECT_REF | |
4214 | && TREE_CONSTANT (TREE_OPERAND (op0, 0))) | |
4215 | return null_pointer_node; | |
4216 | /* Taking the address of a nested function involves a trampoline, | |
4217 | unless we don't need or want one. */ | |
4218 | if (TREE_CODE (op0) == FUNCTION_DECL | |
4219 | && decl_function_context (op0) | |
4220 | && !DECL_NO_STATIC_CHAIN (op0) | |
4221 | && !TREE_NO_TRAMPOLINE (value)) | |
4222 | return NULL_TREE; | |
4223 | /* "&{...}" requires a temporary to hold the constructed | |
4224 | object. */ | |
4225 | if (TREE_CODE (op0) == CONSTRUCTOR) | |
4226 | return NULL_TREE; | |
4227 | } | |
4228 | return op0; | |
4229 | } | |
155b05dc | 4230 | |
4231 | case NON_LVALUE_EXPR: | |
4232 | return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype); | |
4233 | ||
bc103446 | 4234 | case VIEW_CONVERT_EXPR: |
67f29ece | 4235 | { |
bc103446 | 4236 | tree src = TREE_OPERAND (value, 0); |
4237 | tree src_type = TREE_TYPE (src); | |
4238 | tree dest_type = TREE_TYPE (value); | |
4239 | ||
4240 | /* Allow view-conversions from aggregate to non-aggregate type only | |
4241 | if the bit pattern is fully preserved afterwards; otherwise, the | |
4242 | RTL expander won't be able to apply a subsequent transformation | |
4243 | to the underlying constructor. */ | |
4244 | if (AGGREGATE_TYPE_P (src_type) && !AGGREGATE_TYPE_P (dest_type)) | |
4245 | { | |
4246 | if (TYPE_MODE (endtype) == TYPE_MODE (dest_type)) | |
4247 | return initializer_constant_valid_p (src, endtype); | |
4248 | else | |
4249 | return NULL_TREE; | |
4250 | } | |
4251 | ||
4252 | /* Allow all other kinds of view-conversion. */ | |
4253 | return initializer_constant_valid_p (src, endtype); | |
4254 | } | |
67f29ece | 4255 | |
bc103446 | 4256 | CASE_CONVERT: |
4257 | { | |
4258 | tree src = TREE_OPERAND (value, 0); | |
4259 | tree src_type = TREE_TYPE (src); | |
4260 | tree dest_type = TREE_TYPE (value); | |
67f29ece | 4261 | |
4262 | /* Allow conversions between pointer types, floating-point | |
4263 | types, and offset types. */ | |
4264 | if ((POINTER_TYPE_P (dest_type) && POINTER_TYPE_P (src_type)) | |
4265 | || (FLOAT_TYPE_P (dest_type) && FLOAT_TYPE_P (src_type)) | |
4266 | || (TREE_CODE (dest_type) == OFFSET_TYPE | |
4267 | && TREE_CODE (src_type) == OFFSET_TYPE)) | |
4268 | return initializer_constant_valid_p (src, endtype); | |
4269 | ||
4270 | /* Allow length-preserving conversions between integer types. */ | |
4271 | if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type) | |
4272 | && (TYPE_PRECISION (dest_type) == TYPE_PRECISION (src_type))) | |
4273 | return initializer_constant_valid_p (src, endtype); | |
4274 | ||
4275 | /* Allow conversions between other integer types only if | |
4276 | explicit value. */ | |
4277 | if (INTEGRAL_TYPE_P (dest_type) && INTEGRAL_TYPE_P (src_type)) | |
4278 | { | |
4279 | tree inner = initializer_constant_valid_p (src, endtype); | |
4280 | if (inner == null_pointer_node) | |
4281 | return null_pointer_node; | |
4282 | break; | |
4283 | } | |
155b05dc | 4284 | |
67f29ece | 4285 | /* Allow (int) &foo provided int is as wide as a pointer. */ |
4286 | if (INTEGRAL_TYPE_P (dest_type) && POINTER_TYPE_P (src_type) | |
4287 | && (TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type))) | |
4288 | return initializer_constant_valid_p (src, endtype); | |
4289 | ||
4290 | /* Likewise conversions from int to pointers, but also allow | |
4291 | conversions from 0. */ | |
4292 | if ((POINTER_TYPE_P (dest_type) | |
4293 | || TREE_CODE (dest_type) == OFFSET_TYPE) | |
4294 | && INTEGRAL_TYPE_P (src_type)) | |
4295 | { | |
9207f1b3 | 4296 | if (TREE_CODE (src) == INTEGER_CST |
4297 | && TYPE_PRECISION (dest_type) >= TYPE_PRECISION (src_type)) | |
4298 | return null_pointer_node; | |
67f29ece | 4299 | if (integer_zerop (src)) |
4300 | return null_pointer_node; | |
4301 | else if (TYPE_PRECISION (dest_type) <= TYPE_PRECISION (src_type)) | |
4302 | return initializer_constant_valid_p (src, endtype); | |
4303 | } | |
155b05dc | 4304 | |
67f29ece | 4305 | /* Allow conversions to struct or union types if the value |
4306 | inside is okay. */ | |
4307 | if (TREE_CODE (dest_type) == RECORD_TYPE | |
4308 | || TREE_CODE (dest_type) == UNION_TYPE) | |
4309 | return initializer_constant_valid_p (src, endtype); | |
4310 | } | |
155b05dc | 4311 | break; |
4312 | ||
0de36bdb | 4313 | case POINTER_PLUS_EXPR: |
155b05dc | 4314 | case PLUS_EXPR: |
4315 | if (! INTEGRAL_TYPE_P (endtype) | |
4316 | || TYPE_PRECISION (endtype) >= POINTER_SIZE) | |
bc70bd5e | 4317 | { |
155b05dc | 4318 | tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), |
4319 | endtype); | |
4320 | tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), | |
4321 | endtype); | |
7998838c | 4322 | /* If either term is absolute, use the other term's relocation. */ |
155b05dc | 4323 | if (valid0 == null_pointer_node) |
4324 | return valid1; | |
4325 | if (valid1 == null_pointer_node) | |
4326 | return valid0; | |
bc70bd5e | 4327 | } |
2d0e6843 | 4328 | |
4329 | /* Support narrowing pointer differences. */ | |
a9d778f8 | 4330 | ret = narrowing_initializer_constant_valid_p (value, endtype); |
4331 | if (ret != NULL_TREE) | |
4332 | return ret; | |
4333 | ||
155b05dc | 4334 | break; |
4335 | ||
4336 | case MINUS_EXPR: | |
4337 | if (! INTEGRAL_TYPE_P (endtype) | |
4338 | || TYPE_PRECISION (endtype) >= POINTER_SIZE) | |
4339 | { | |
4340 | tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0), | |
4341 | endtype); | |
4342 | tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1), | |
4343 | endtype); | |
4344 | /* Win if second argument is absolute. */ | |
4345 | if (valid1 == null_pointer_node) | |
4346 | return valid0; | |
4347 | /* Win if both arguments have the same relocation. | |
4348 | Then the value is absolute. */ | |
4349 | if (valid0 == valid1 && valid0 != 0) | |
4350 | return null_pointer_node; | |
77ed70ed | 4351 | |
4352 | /* Since GCC guarantees that string constants are unique in the | |
4353 | generated code, a subtraction between two copies of the same | |
4354 | constant string is absolute. */ | |
7da1265c | 4355 | if (valid0 && TREE_CODE (valid0) == STRING_CST |
4356 | && valid1 && TREE_CODE (valid1) == STRING_CST | |
4357 | && operand_equal_p (valid0, valid1, 1)) | |
77ed70ed | 4358 | return null_pointer_node; |
155b05dc | 4359 | } |
4360 | ||
7da1265c | 4361 | /* Support narrowing differences. */ |
2d0e6843 | 4362 | ret = narrowing_initializer_constant_valid_p (value, endtype); |
4363 | if (ret != NULL_TREE) | |
4364 | return ret; | |
7da1265c | 4365 | |
155b05dc | 4366 | break; |
4367 | ||
4368 | default: | |
4369 | break; | |
4370 | } | |
4371 | ||
4372 | return 0; | |
4373 | } | |
4374 | \f | |
34a6a65d | 4375 | /* Return true if VALUE is a valid constant-valued expression |
4376 | for use in initializing a static bit-field; one that can be | |
4377 | an element of a "constant" initializer. */ | |
4378 | ||
4379 | bool | |
4380 | initializer_constant_valid_for_bitfield_p (tree value) | |
4381 | { | |
4382 | /* For bitfields we support integer constants or possibly nested aggregates | |
4383 | of such. */ | |
4384 | switch (TREE_CODE (value)) | |
4385 | { | |
4386 | case CONSTRUCTOR: | |
4387 | { | |
4388 | unsigned HOST_WIDE_INT idx; | |
4389 | tree elt; | |
4390 | ||
4391 | FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (value), idx, elt) | |
4392 | if (!initializer_constant_valid_for_bitfield_p (elt)) | |
4393 | return false; | |
4394 | return true; | |
4395 | } | |
4396 | ||
4397 | case INTEGER_CST: | |
4398 | return true; | |
4399 | ||
4400 | case VIEW_CONVERT_EXPR: | |
4401 | case NON_LVALUE_EXPR: | |
4402 | return | |
4403 | initializer_constant_valid_for_bitfield_p (TREE_OPERAND (value, 0)); | |
4404 | ||
4405 | default: | |
4406 | break; | |
4407 | } | |
4408 | ||
4409 | return false; | |
4410 | } | |
4411 | ||
4412 | /* output_constructor outer state of relevance in recursive calls, typically | |
4413 | for nested aggregate bitfields. */ | |
4414 | ||
4415 | typedef struct { | |
4416 | unsigned int bit_offset; /* current position in ... */ | |
4417 | int byte; /* ... the outer byte buffer. */ | |
4418 | } oc_outer_state; | |
4419 | ||
4420 | static unsigned HOST_WIDE_INT | |
4421 | output_constructor (tree, unsigned HOST_WIDE_INT, unsigned int, | |
4422 | oc_outer_state *); | |
4423 | ||
5243fbff | 4424 | /* Output assembler code for constant EXP to FILE, with no label. |
4425 | This includes the pseudo-op such as ".int" or ".byte", and a newline. | |
4426 | Assumes output_addressed_constants has been done on EXP already. | |
4427 | ||
4428 | Generate exactly SIZE bytes of assembler data, padding at the end | |
4429 | with zeros if necessary. SIZE must always be specified. | |
4430 | ||
4431 | SIZE is important for structure constructors, | |
4432 | since trailing members may have been omitted from the constructor. | |
4433 | It is also important for initialization of arrays from string constants | |
4434 | since the full length of the string constant might not be wanted. | |
4435 | It is also needed for initialization of unions, where the initializer's | |
4436 | type is just one member, and that may not be as long as the union. | |
4437 | ||
4438 | There a case in which we would fail to output exactly SIZE bytes: | |
4439 | for a structure constructor that wants to produce more than SIZE bytes. | |
09d688ff | 4440 | But such constructors will never be generated for any possible input. |
4441 | ||
4442 | ALIGN is the alignment of the data in bits. */ | |
5243fbff | 4443 | |
4444 | void | |
3180a54f | 4445 | output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align) |
5243fbff | 4446 | { |
b3187c7c | 4447 | enum tree_code code; |
d716c068 | 4448 | unsigned HOST_WIDE_INT thissize; |
5243fbff | 4449 | |
785f5424 | 4450 | if (size == 0 || flag_syntax_only) |
5243fbff | 4451 | return; |
4452 | ||
c7756fad | 4453 | /* See if we're trying to initialize a pointer in a non-default mode |
5e0d5629 | 4454 | to the address of some declaration somewhere. If the target says |
4455 | the mode is valid for pointers, assume the target has a way of | |
4456 | resolving it. */ | |
4457 | if (TREE_CODE (exp) == NOP_EXPR | |
4458 | && POINTER_TYPE_P (TREE_TYPE (exp)) | |
4459 | && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp)))) | |
4460 | { | |
4461 | tree saved_type = TREE_TYPE (exp); | |
4462 | ||
4463 | /* Peel off any intermediate conversions-to-pointer for valid | |
4464 | pointer modes. */ | |
4465 | while (TREE_CODE (exp) == NOP_EXPR | |
4466 | && POINTER_TYPE_P (TREE_TYPE (exp)) | |
4467 | && targetm.valid_pointer_mode (TYPE_MODE (TREE_TYPE (exp)))) | |
4468 | exp = TREE_OPERAND (exp, 0); | |
4469 | ||
4470 | /* If what we're left with is the address of something, we can | |
4471 | convert the address to the final type and output it that | |
4472 | way. */ | |
4473 | if (TREE_CODE (exp) == ADDR_EXPR) | |
4474 | exp = build1 (ADDR_EXPR, saved_type, TREE_OPERAND (exp, 0)); | |
9207f1b3 | 4475 | /* Likewise for constant ints. */ |
4476 | else if (TREE_CODE (exp) == INTEGER_CST) | |
4477 | exp = build_int_cst_wide (saved_type, TREE_INT_CST_LOW (exp), | |
4478 | TREE_INT_CST_HIGH (exp)); | |
4479 | ||
5e0d5629 | 4480 | } |
4481 | ||
b3187c7c | 4482 | /* Eliminate any conversions since we'll be outputting the underlying |
4483 | constant. */ | |
72dd6141 | 4484 | while (CONVERT_EXPR_P (exp) |
f96c43fb | 4485 | || TREE_CODE (exp) == NON_LVALUE_EXPR |
4486 | || TREE_CODE (exp) == VIEW_CONVERT_EXPR) | |
5e0d5629 | 4487 | { |
4488 | HOST_WIDE_INT type_size = int_size_in_bytes (TREE_TYPE (exp)); | |
4489 | HOST_WIDE_INT op_size = int_size_in_bytes (TREE_TYPE (TREE_OPERAND (exp, 0))); | |
4490 | ||
6f6c3ae6 | 4491 | /* Make sure eliminating the conversion is really a no-op, except with |
0b5a232a | 4492 | VIEW_CONVERT_EXPRs to allow for wild Ada unchecked conversions and |
4493 | union types to allow for Ada unchecked unions. */ | |
45eca001 | 4494 | if (type_size > op_size |
0b5a232a | 4495 | && TREE_CODE (exp) != VIEW_CONVERT_EXPR |
4496 | && TREE_CODE (TREE_TYPE (exp)) != UNION_TYPE) | |
f3fd6db7 | 4497 | /* Keep the conversion. */ |
4498 | break; | |
4499 | else | |
4500 | exp = TREE_OPERAND (exp, 0); | |
5e0d5629 | 4501 | } |
b3187c7c | 4502 | |
4503 | code = TREE_CODE (TREE_TYPE (exp)); | |
4504 | thissize = int_size_in_bytes (TREE_TYPE (exp)); | |
81d7051e | 4505 | |
a6e4a944 | 4506 | /* Allow a constructor with no elements for any data type. |
4507 | This means to fill the space with zeros. */ | |
c75b4594 | 4508 | if (TREE_CODE (exp) == CONSTRUCTOR |
4509 | && VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (exp))) | |
a6e4a944 | 4510 | { |
b54842d8 | 4511 | assemble_zeros (size); |
a6e4a944 | 4512 | return; |
4513 | } | |
4514 | ||
6bfa2cc1 | 4515 | if (TREE_CODE (exp) == FDESC_EXPR) |
4516 | { | |
347ed1c0 | 4517 | #ifdef ASM_OUTPUT_FDESC |
6bfa2cc1 | 4518 | HOST_WIDE_INT part = tree_low_cst (TREE_OPERAND (exp, 1), 0); |
4519 | tree decl = TREE_OPERAND (exp, 0); | |
6bfa2cc1 | 4520 | ASM_OUTPUT_FDESC (asm_out_file, decl, part); |
4521 | #else | |
22167fd5 | 4522 | gcc_unreachable (); |
6bfa2cc1 | 4523 | #endif |
4524 | return; | |
4525 | } | |
4526 | ||
b3187c7c | 4527 | /* Now output the underlying data. If we've handling the padding, return. |
3e29f5cd | 4528 | Otherwise, break and ensure SIZE is the size written. */ |
5243fbff | 4529 | switch (code) |
4530 | { | |
164f28b2 | 4531 | case BOOLEAN_TYPE: |
5243fbff | 4532 | case INTEGER_TYPE: |
4533 | case ENUMERAL_TYPE: | |
4534 | case POINTER_TYPE: | |
4535 | case REFERENCE_TYPE: | |
1bc16cab | 4536 | case OFFSET_TYPE: |
e397ad8e | 4537 | case FIXED_POINT_TYPE: |
89e66659 | 4538 | if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode, |
5243fbff | 4539 | EXPAND_INITIALIZER), |
3e29f5cd | 4540 | MIN (size, thissize), align, 0)) |
e397ad8e | 4541 | error ("initializer for integer/fixed-point value is too complicated"); |
5243fbff | 4542 | break; |
4543 | ||
4544 | case REAL_TYPE: | |
4545 | if (TREE_CODE (exp) != REAL_CST) | |
4546 | error ("initializer for floating value is not a floating constant"); | |
4547 | ||
b8bc42e9 | 4548 | assemble_real (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)), align); |
5243fbff | 4549 | break; |
4550 | ||
4551 | case COMPLEX_TYPE: | |
b3187c7c | 4552 | output_constant (TREE_REALPART (exp), thissize / 2, align); |
4553 | output_constant (TREE_IMAGPART (exp), thissize / 2, | |
4554 | min_align (align, BITS_PER_UNIT * (thissize / 2))); | |
5243fbff | 4555 | break; |
4556 | ||
4557 | case ARRAY_TYPE: | |
0ad236c2 | 4558 | case VECTOR_TYPE: |
22167fd5 | 4559 | switch (TREE_CODE (exp)) |
5243fbff | 4560 | { |
22167fd5 | 4561 | case CONSTRUCTOR: |
34a6a65d | 4562 | output_constructor (exp, size, align, NULL); |
5243fbff | 4563 | return; |
22167fd5 | 4564 | case STRING_CST: |
d716c068 | 4565 | thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp), |
4566 | size); | |
b3187c7c | 4567 | assemble_string (TREE_STRING_POINTER (exp), thissize); |
22167fd5 | 4568 | break; |
c3309fc6 | 4569 | |
22167fd5 | 4570 | case VECTOR_CST: |
4571 | { | |
4572 | int elt_size; | |
4573 | tree link; | |
4574 | unsigned int nalign; | |
4575 | enum machine_mode inner; | |
b215c058 | 4576 | |
22167fd5 | 4577 | inner = TYPE_MODE (TREE_TYPE (TREE_TYPE (exp))); |
4578 | nalign = MIN (align, GET_MODE_ALIGNMENT (inner)); | |
b215c058 | 4579 | |
22167fd5 | 4580 | elt_size = GET_MODE_SIZE (inner); |
b215c058 | 4581 | |
22167fd5 | 4582 | link = TREE_VECTOR_CST_ELTS (exp); |
4583 | output_constant (TREE_VALUE (link), elt_size, align); | |
69d99d08 | 4584 | thissize = elt_size; |
22167fd5 | 4585 | while ((link = TREE_CHAIN (link)) != NULL) |
69d99d08 | 4586 | { |
4587 | output_constant (TREE_VALUE (link), elt_size, nalign); | |
4588 | thissize += elt_size; | |
4589 | } | |
22167fd5 | 4590 | break; |
4591 | } | |
4592 | default: | |
4593 | gcc_unreachable (); | |
c3309fc6 | 4594 | } |
5243fbff | 4595 | break; |
4596 | ||
4597 | case RECORD_TYPE: | |
4598 | case UNION_TYPE: | |
22167fd5 | 4599 | gcc_assert (TREE_CODE (exp) == CONSTRUCTOR); |
34a6a65d | 4600 | output_constructor (exp, size, align, NULL); |
5243fbff | 4601 | return; |
b9bc495a | 4602 | |
0427bbfb | 4603 | case ERROR_MARK: |
4604 | return; | |
4605 | ||
0dbd1c74 | 4606 | default: |
22167fd5 | 4607 | gcc_unreachable (); |
5243fbff | 4608 | } |
4609 | ||
c62e29e1 | 4610 | if (size > thissize) |
4611 | assemble_zeros (size - thissize); | |
5243fbff | 4612 | } |
649d8da6 | 4613 | |
5243fbff | 4614 | \f |
1b82e858 | 4615 | /* Subroutine of output_constructor, used for computing the size of |
4616 | arrays of unspecified length. VAL must be a CONSTRUCTOR of an array | |
4617 | type with an unspecified upper bound. */ | |
4618 | ||
21c8999d | 4619 | static unsigned HOST_WIDE_INT |
3180a54f | 4620 | array_size_for_constructor (tree val) |
1b82e858 | 4621 | { |
4622 | tree max_index, i; | |
c75b4594 | 4623 | unsigned HOST_WIDE_INT cnt; |
535664e3 | 4624 | tree index, value, tmp; |
1b82e858 | 4625 | |
b3187c7c | 4626 | /* This code used to attempt to handle string constants that are not |
4627 | arrays of single-bytes, but nothing else does, so there's no point in | |
4628 | doing it here. */ | |
347e5e07 | 4629 | if (TREE_CODE (val) == STRING_CST) |
b3187c7c | 4630 | return TREE_STRING_LENGTH (val); |
4631 | ||
1b82e858 | 4632 | max_index = NULL_TREE; |
c75b4594 | 4633 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (val), cnt, index, value) |
1b82e858 | 4634 | { |
1b82e858 | 4635 | if (TREE_CODE (index) == RANGE_EXPR) |
4636 | index = TREE_OPERAND (index, 1); | |
4637 | if (max_index == NULL_TREE || tree_int_cst_lt (max_index, index)) | |
4638 | max_index = index; | |
4639 | } | |
4640 | ||
1b82e858 | 4641 | if (max_index == NULL_TREE) |
21c8999d | 4642 | return 0; |
1b82e858 | 4643 | |
4644 | /* Compute the total number of array elements. */ | |
535664e3 | 4645 | tmp = TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (val))); |
4646 | i = size_binop (MINUS_EXPR, fold_convert (sizetype, max_index), | |
4647 | fold_convert (sizetype, tmp)); | |
3c6185f1 | 4648 | i = size_binop (PLUS_EXPR, i, build_int_cst (sizetype, 1)); |
1b82e858 | 4649 | |
4650 | /* Multiply by the array element unit size to find number of bytes. */ | |
21c8999d | 4651 | i = size_binop (MULT_EXPR, i, TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (val)))); |
1b82e858 | 4652 | |
4653 | return tree_low_cst (i, 1); | |
4654 | } | |
4655 | ||
34a6a65d | 4656 | /* Other datastructures + helpers for output_constructor. */ |
5243fbff | 4657 | |
34a6a65d | 4658 | /* output_constructor local state to support interaction with helpers. */ |
5243fbff | 4659 | |
34a6a65d | 4660 | typedef struct { |
5243fbff | 4661 | |
34a6a65d | 4662 | /* Received arguments. */ |
4663 | tree exp; /* Constructor expression. */ | |
4664 | unsigned HOST_WIDE_INT size; /* # bytes to output - pad if necessary. */ | |
4665 | unsigned int align; /* Known initial alignment. */ | |
5243fbff | 4666 | |
34a6a65d | 4667 | /* Constructor expression data. */ |
4668 | tree type; /* Expression type. */ | |
4669 | tree field; /* Current field decl in a record. */ | |
4670 | tree min_index; /* Lower bound if specified for an array. */ | |
cfcb6f0b | 4671 | |
34a6a65d | 4672 | /* Output processing state. */ |
4673 | HOST_WIDE_INT total_bytes; /* # bytes output so far / current position. */ | |
4674 | bool byte_buffer_in_use; /* Whether byte ... */ | |
4675 | int byte; /* ... contains part of a bitfield byte yet to | |
4676 | be output. */ | |
374e1d5f | 4677 | |
34a6a65d | 4678 | int last_relative_index; /* Implicit or explicit index of the last |
4679 | array element output within a bitfield. */ | |
4680 | /* Current element. */ | |
4681 | tree val; /* Current element value. */ | |
4682 | tree index; /* Current element index. */ | |
4683 | ||
4684 | } oc_local_state; | |
4685 | ||
4686 | /* Helper for output_constructor. From the current LOCAL state, output a | |
4687 | RANGE_EXPR element. */ | |
4688 | ||
4689 | static void | |
4690 | output_constructor_array_range (oc_local_state *local) | |
4691 | { | |
4692 | unsigned HOST_WIDE_INT fieldsize | |
4693 | = int_size_in_bytes (TREE_TYPE (local->type)); | |
4694 | ||
4695 | HOST_WIDE_INT lo_index | |
4696 | = tree_low_cst (TREE_OPERAND (local->index, 0), 0); | |
4697 | HOST_WIDE_INT hi_index | |
4698 | = tree_low_cst (TREE_OPERAND (local->index, 1), 0); | |
4699 | HOST_WIDE_INT index; | |
4700 | ||
4701 | unsigned int align2 | |
4702 | = min_align (local->align, fieldsize * BITS_PER_UNIT); | |
4703 | ||
4704 | for (index = lo_index; index <= hi_index; index++) | |
5243fbff | 4705 | { |
34a6a65d | 4706 | /* Output the element's initial value. */ |
4707 | if (local->val == NULL_TREE) | |
4708 | assemble_zeros (fieldsize); | |
4709 | else | |
4710 | output_constant (local->val, fieldsize, align2); | |
4711 | ||
4712 | /* Count its size. */ | |
4713 | local->total_bytes += fieldsize; | |
4714 | } | |
4715 | } | |
ff1c73fe | 4716 | |
34a6a65d | 4717 | /* Helper for output_constructor. From the current LOCAL state, output a |
4718 | field element that is not true bitfield or part of an outer one. */ | |
4719 | ||
4720 | static void | |
4721 | output_constructor_regular_field (oc_local_state *local) | |
4722 | { | |
4723 | /* Field size and position. Since this structure is static, we know the | |
4724 | positions are constant. */ | |
4725 | unsigned HOST_WIDE_INT fieldsize; | |
4726 | HOST_WIDE_INT fieldpos; | |
ff1c73fe | 4727 | |
34a6a65d | 4728 | unsigned int align2; |
ff1c73fe | 4729 | |
34a6a65d | 4730 | if (local->index != NULL_TREE) |
4731 | fieldpos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (local->val)), 1) | |
4732 | * ((tree_low_cst (local->index, 0) | |
4733 | - tree_low_cst (local->min_index, 0)))); | |
4734 | else if (local->field != NULL_TREE) | |
4735 | fieldpos = int_byte_position (local->field); | |
4736 | else | |
4737 | fieldpos = 0; | |
1cfa4bdd | 4738 | |
34a6a65d | 4739 | /* Output any buffered-up bit-fields preceding this element. */ |
4740 | if (local->byte_buffer_in_use) | |
4741 | { | |
4742 | assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1); | |
4743 | local->total_bytes++; | |
4744 | local->byte_buffer_in_use = false; | |
4745 | } | |
4746 | ||
4747 | /* Advance to offset of this element. | |
4748 | Note no alignment needed in an array, since that is guaranteed | |
4749 | if each element has the proper size. */ | |
4750 | if ((local->field != NULL_TREE || local->index != NULL_TREE) | |
4751 | && fieldpos != local->total_bytes) | |
4752 | { | |
4753 | gcc_assert (fieldpos >= local->total_bytes); | |
4754 | assemble_zeros (fieldpos - local->total_bytes); | |
4755 | local->total_bytes = fieldpos; | |
4756 | } | |
4757 | ||
4758 | /* Find the alignment of this element. */ | |
4759 | align2 = min_align (local->align, BITS_PER_UNIT * fieldpos); | |
5243fbff | 4760 | |
34a6a65d | 4761 | /* Determine size this element should occupy. */ |
4762 | if (local->field) | |
4763 | { | |
4764 | fieldsize = 0; | |
4765 | ||
4766 | /* If this is an array with an unspecified upper bound, | |
4767 | the initializer determines the size. */ | |
4768 | /* ??? This ought to only checked if DECL_SIZE_UNIT is NULL, | |
4769 | but we cannot do this until the deprecated support for | |
4770 | initializing zero-length array members is removed. */ | |
4771 | if (TREE_CODE (TREE_TYPE (local->field)) == ARRAY_TYPE | |
4772 | && TYPE_DOMAIN (TREE_TYPE (local->field)) | |
4773 | && ! TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (local->field)))) | |
865c4b7a | 4774 | { |
34a6a65d | 4775 | fieldsize = array_size_for_constructor (local->val); |
4776 | /* Given a non-empty initialization, this field had | |
4777 | better be last. */ | |
4778 | gcc_assert (!fieldsize || !TREE_CHAIN (local->field)); | |
865c4b7a | 4779 | } |
34a6a65d | 4780 | else if (DECL_SIZE_UNIT (local->field)) |
5243fbff | 4781 | { |
34a6a65d | 4782 | /* ??? This can't be right. If the decl size overflows |
4783 | a host integer we will silently emit no data. */ | |
4784 | if (host_integerp (DECL_SIZE_UNIT (local->field), 1)) | |
4785 | fieldsize = tree_low_cst (DECL_SIZE_UNIT (local->field), 1); | |
4786 | } | |
4787 | } | |
4788 | else | |
4789 | fieldsize = int_size_in_bytes (TREE_TYPE (local->type)); | |
4790 | ||
4791 | /* Output the element's initial value. */ | |
4792 | if (local->val == NULL_TREE) | |
4793 | assemble_zeros (fieldsize); | |
4794 | else | |
4795 | output_constant (local->val, fieldsize, align2); | |
02e7a332 | 4796 | |
34a6a65d | 4797 | /* Count its size. */ |
4798 | local->total_bytes += fieldsize; | |
4799 | } | |
5243fbff | 4800 | |
34a6a65d | 4801 | /* Helper for output_constructor. From the current LOCAL and OUTER states, |
4802 | output an element that is a true bitfield or part of an outer one. */ | |
5243fbff | 4803 | |
34a6a65d | 4804 | static void |
4805 | output_constructor_bitfield (oc_local_state *local, oc_outer_state *outer) | |
4806 | { | |
4807 | /* Bit size of this element. */ | |
4808 | HOST_WIDE_INT ebitsize | |
4809 | = (local->field | |
4810 | ? tree_low_cst (DECL_SIZE (local->field), 1) | |
4811 | : tree_low_cst (TYPE_SIZE (TREE_TYPE (local->type)), 1)); | |
4812 | ||
4813 | /* Relative index of this element if this is an array component. */ | |
4814 | HOST_WIDE_INT relative_index | |
4815 | = (!local->field | |
4816 | ? (local->index | |
4817 | ? (tree_low_cst (local->index, 0) | |
4818 | - tree_low_cst (local->min_index, 0)) | |
4819 | : local->last_relative_index + 1) | |
4820 | : 0); | |
4821 | ||
4822 | /* Bit position of this element from the start of the containing | |
4823 | constructor. */ | |
4824 | HOST_WIDE_INT constructor_relative_ebitpos | |
4825 | = (local->field | |
4826 | ? int_bit_position (local->field) | |
4827 | : ebitsize * relative_index); | |
4828 | ||
4829 | /* Bit position of this element from the start of a possibly ongoing | |
4830 | outer byte buffer. */ | |
4831 | HOST_WIDE_INT byte_relative_ebitpos | |
4832 | = ((outer ? outer->bit_offset : 0) + constructor_relative_ebitpos); | |
4833 | ||
4834 | /* From the start of a possibly ongoing outer byte buffer, offsets to | |
4835 | the first bit of this element and to the first bit past the end of | |
4836 | this element. */ | |
4837 | HOST_WIDE_INT next_offset = byte_relative_ebitpos; | |
4838 | HOST_WIDE_INT end_offset = byte_relative_ebitpos + ebitsize; | |
4839 | ||
4840 | local->last_relative_index = relative_index; | |
4841 | ||
4842 | if (local->val == NULL_TREE) | |
4843 | local->val = integer_zero_node; | |
4844 | ||
4845 | while (TREE_CODE (local->val) == VIEW_CONVERT_EXPR | |
4846 | || TREE_CODE (local->val) == NON_LVALUE_EXPR) | |
4847 | local->val = TREE_OPERAND (local->val, 0); | |
4848 | ||
4849 | if (TREE_CODE (local->val) != INTEGER_CST | |
4850 | && TREE_CODE (local->val) != CONSTRUCTOR) | |
4851 | { | |
4852 | error ("invalid initial value for member %qE", DECL_NAME (local->field)); | |
4853 | return; | |
4854 | } | |
a3b9fc2f | 4855 | |
34a6a65d | 4856 | /* If this field does not start in this (or, next) byte, |
4857 | skip some bytes. */ | |
4858 | if (next_offset / BITS_PER_UNIT != local->total_bytes) | |
4859 | { | |
4860 | /* Output remnant of any bit field in previous bytes. */ | |
4861 | if (local->byte_buffer_in_use) | |
4862 | { | |
4863 | assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1); | |
4864 | local->total_bytes++; | |
4865 | local->byte_buffer_in_use = false; | |
4866 | } | |
4867 | ||
4868 | /* If still not at proper byte, advance to there. */ | |
4869 | if (next_offset / BITS_PER_UNIT != local->total_bytes) | |
4870 | { | |
4871 | gcc_assert (next_offset / BITS_PER_UNIT >= local->total_bytes); | |
4872 | assemble_zeros (next_offset / BITS_PER_UNIT - local->total_bytes); | |
4873 | local->total_bytes = next_offset / BITS_PER_UNIT; | |
4874 | } | |
4875 | } | |
4876 | ||
4877 | /* Set up the buffer if necessary. */ | |
4878 | if (!local->byte_buffer_in_use) | |
4879 | { | |
4880 | local->byte = 0; | |
4881 | if (ebitsize > 0) | |
4882 | local->byte_buffer_in_use = true; | |
4883 | } | |
4884 | ||
4885 | /* If this is nested constructor, recurse passing the bit offset and the | |
4886 | pending data, then retrieve the new pending data afterwards. */ | |
4887 | if (TREE_CODE (local->val) == CONSTRUCTOR) | |
4888 | { | |
4889 | oc_outer_state output_state; | |
b7fdac4b | 4890 | |
34a6a65d | 4891 | output_state.bit_offset = next_offset % BITS_PER_UNIT; |
4892 | output_state.byte = local->byte; | |
4893 | local->total_bytes | |
4894 | += output_constructor (local->val, 0, 0, &output_state); | |
4895 | local->byte = output_state.byte; | |
4896 | return; | |
4897 | } | |
4898 | ||
4899 | /* Otherwise, we must split the element into pieces that fall within | |
4900 | separate bytes, and combine each byte with previous or following | |
4901 | bit-fields. */ | |
4902 | while (next_offset < end_offset) | |
4903 | { | |
4904 | int this_time; | |
4905 | int shift; | |
4906 | HOST_WIDE_INT value; | |
4907 | HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT; | |
4908 | HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT; | |
4909 | ||
4910 | /* Advance from byte to byte | |
4911 | within this element when necessary. */ | |
4912 | while (next_byte != local->total_bytes) | |
4913 | { | |
4914 | assemble_integer (GEN_INT (local->byte), 1, BITS_PER_UNIT, 1); | |
4915 | local->total_bytes++; | |
4916 | local->byte = 0; | |
4917 | } | |
4918 | ||
4919 | /* Number of bits we can process at once | |
4920 | (all part of the same byte). */ | |
4921 | this_time = MIN (end_offset - next_offset, | |
4922 | BITS_PER_UNIT - next_bit); | |
4923 | if (BYTES_BIG_ENDIAN) | |
4924 | { | |
4925 | /* On big-endian machine, take the most significant bits | |
4926 | first (of the bits that are significant) | |
4927 | and put them into bytes from the most significant end. */ | |
4928 | shift = end_offset - next_offset - this_time; | |
4929 | ||
4930 | /* Don't try to take a bunch of bits that cross | |
4931 | the word boundary in the INTEGER_CST. We can | |
4932 | only select bits from the LOW or HIGH part | |
4933 | not from both. */ | |
4934 | if (shift < HOST_BITS_PER_WIDE_INT | |
4935 | && shift + this_time > HOST_BITS_PER_WIDE_INT) | |
1b82e858 | 4936 | { |
34a6a65d | 4937 | this_time = shift + this_time - HOST_BITS_PER_WIDE_INT; |
4938 | shift = HOST_BITS_PER_WIDE_INT; | |
1b82e858 | 4939 | } |
34a6a65d | 4940 | |
4941 | /* Now get the bits from the appropriate constant word. */ | |
4942 | if (shift < HOST_BITS_PER_WIDE_INT) | |
4943 | value = TREE_INT_CST_LOW (local->val); | |
5243fbff | 4944 | else |
34a6a65d | 4945 | { |
4946 | gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT); | |
4947 | value = TREE_INT_CST_HIGH (local->val); | |
4948 | shift -= HOST_BITS_PER_WIDE_INT; | |
4949 | } | |
4950 | ||
4951 | /* Get the result. This works only when: | |
4952 | 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ | |
4953 | local->byte |= (((value >> shift) | |
4954 | & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) | |
4955 | << (BITS_PER_UNIT - this_time - next_bit)); | |
5243fbff | 4956 | } |
5243fbff | 4957 | else |
4958 | { | |
34a6a65d | 4959 | /* On little-endian machines, |
4960 | take first the least significant bits of the value | |
4961 | and pack them starting at the least significant | |
4962 | bits of the bytes. */ | |
4963 | shift = next_offset - byte_relative_ebitpos; | |
4964 | ||
4965 | /* Don't try to take a bunch of bits that cross | |
4966 | the word boundary in the INTEGER_CST. We can | |
4967 | only select bits from the LOW or HIGH part | |
4968 | not from both. */ | |
4969 | if (shift < HOST_BITS_PER_WIDE_INT | |
4970 | && shift + this_time > HOST_BITS_PER_WIDE_INT) | |
4971 | this_time = (HOST_BITS_PER_WIDE_INT - shift); | |
4972 | ||
4973 | /* Now get the bits from the appropriate constant word. */ | |
4974 | if (shift < HOST_BITS_PER_WIDE_INT) | |
4975 | value = TREE_INT_CST_LOW (local->val); | |
4976 | else | |
4977 | { | |
4978 | gcc_assert (shift < 2 * HOST_BITS_PER_WIDE_INT); | |
4979 | value = TREE_INT_CST_HIGH (local->val); | |
4980 | shift -= HOST_BITS_PER_WIDE_INT; | |
4981 | } | |
4982 | ||
4983 | /* Get the result. This works only when: | |
4984 | 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */ | |
4985 | local->byte |= (((value >> shift) | |
4986 | & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1)) | |
4987 | << next_bit); | |
4988 | } | |
4989 | ||
4990 | next_offset += this_time; | |
4991 | local->byte_buffer_in_use = true; | |
4992 | } | |
4993 | } | |
4994 | ||
4995 | /* Subroutine of output_constant, used for CONSTRUCTORs (aggregate constants). | |
4996 | Generate at least SIZE bytes, padding if necessary. OUTER designates the | |
4997 | caller output state of relevance in recursive invocations. */ | |
4998 | ||
4999 | static unsigned HOST_WIDE_INT | |
5000 | output_constructor (tree exp, unsigned HOST_WIDE_INT size, | |
5001 | unsigned int align, oc_outer_state * outer) | |
5002 | { | |
5003 | unsigned HOST_WIDE_INT cnt; | |
5004 | constructor_elt *ce; | |
5243fbff | 5005 | |
34a6a65d | 5006 | oc_local_state local; |
5243fbff | 5007 | |
34a6a65d | 5008 | /* Setup our local state to communicate with helpers. */ |
5009 | local.exp = exp; | |
5010 | local.size = size; | |
5011 | local.align = align; | |
5243fbff | 5012 | |
34a6a65d | 5013 | local.total_bytes = 0; |
5014 | local.byte_buffer_in_use = outer != NULL; | |
5015 | local.byte = outer ? outer->byte : 0; | |
5243fbff | 5016 | |
34a6a65d | 5017 | local.type = TREE_TYPE (exp); |
5243fbff | 5018 | |
34a6a65d | 5019 | local.last_relative_index = -1; |
5243fbff | 5020 | |
34a6a65d | 5021 | local.min_index = NULL_TREE; |
5022 | if (TREE_CODE (local.type) == ARRAY_TYPE | |
5023 | && TYPE_DOMAIN (local.type) != NULL_TREE) | |
5024 | local.min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (local.type)); | |
5025 | ||
5026 | gcc_assert (HOST_BITS_PER_WIDE_INT >= BITS_PER_UNIT); | |
5027 | ||
5028 | /* As CE goes through the elements of the constant, FIELD goes through the | |
5029 | structure fields if the constant is a structure. If the constant is a | |
5030 | union, we override this by getting the field from the TREE_LIST element. | |
5031 | But the constant could also be an array. Then FIELD is zero. | |
84554bf9 | 5032 | |
34a6a65d | 5033 | There is always a maximum of one element in the chain LINK for unions |
5034 | (even if the initializer in a source program incorrectly contains | |
5035 | more one). */ | |
5036 | ||
5037 | local.field = NULL_TREE; | |
5038 | if (TREE_CODE (local.type) == RECORD_TYPE) | |
5039 | local.field = TYPE_FIELDS (local.type); | |
5040 | ||
5041 | for (cnt = 0; | |
5042 | VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), cnt, ce); | |
5043 | cnt++, local.field = local.field ? TREE_CHAIN (local.field) : 0) | |
5243fbff | 5044 | { |
34a6a65d | 5045 | local.val = ce->value; |
5046 | local.index = NULL_TREE; | |
5047 | ||
5048 | /* The element in a union constructor specifies the proper field | |
5049 | or index. */ | |
5050 | if ((TREE_CODE (local.type) == RECORD_TYPE | |
5051 | || TREE_CODE (local.type) == UNION_TYPE | |
5052 | || TREE_CODE (local.type) == QUAL_UNION_TYPE) | |
5053 | && ce->index != NULL_TREE) | |
5054 | local.field = ce->index; | |
5055 | ||
5056 | else if (TREE_CODE (local.type) == ARRAY_TYPE) | |
5057 | local.index = ce->index; | |
5058 | ||
5059 | #ifdef ASM_COMMENT_START | |
5060 | if (local.field && flag_verbose_asm) | |
5061 | fprintf (asm_out_file, "%s %s:\n", | |
5062 | ASM_COMMENT_START, | |
5063 | DECL_NAME (local.field) | |
5064 | ? IDENTIFIER_POINTER (DECL_NAME (local.field)) | |
5065 | : "<anonymous>"); | |
5066 | #endif | |
5067 | ||
5068 | /* Eliminate the marker that makes a cast not be an lvalue. */ | |
5069 | if (local.val != NULL_TREE) | |
5070 | STRIP_NOPS (local.val); | |
5071 | ||
5072 | /* Output the current element, using the appropriate helper ... */ | |
5073 | ||
5074 | /* For an array slice not part of an outer bitfield. */ | |
5075 | if (!outer | |
5076 | && local.index != NULL_TREE | |
5077 | && TREE_CODE (local.index) == RANGE_EXPR) | |
5078 | output_constructor_array_range (&local); | |
5079 | ||
5080 | /* For a field that is neither a true bitfield nor part of an outer one, | |
5081 | known to be at least byte aligned and multiple-of-bytes long. */ | |
5082 | else if (!outer | |
5083 | && (local.field == NULL_TREE | |
5084 | || !CONSTRUCTOR_BITFIELD_P (local.field))) | |
5085 | output_constructor_regular_field (&local); | |
5086 | ||
5087 | /* For a true bitfield or part of an outer one. */ | |
5088 | else | |
5089 | output_constructor_bitfield (&local, outer); | |
5243fbff | 5090 | } |
84554bf9 | 5091 | |
34a6a65d | 5092 | /* If we are not at toplevel, save the pending data for our caller. |
5093 | Otherwise output the pending data and padding zeros as needed. */ | |
5094 | if (outer) | |
5095 | outer->byte = local.byte; | |
5096 | else | |
5097 | { | |
5098 | if (local.byte_buffer_in_use) | |
5099 | { | |
5100 | assemble_integer (GEN_INT (local.byte), 1, BITS_PER_UNIT, 1); | |
5101 | local.total_bytes++; | |
5102 | } | |
5103 | ||
5104 | if ((unsigned HOST_WIDE_INT)local.total_bytes < local.size) | |
5105 | { | |
5106 | assemble_zeros (local.size - local.total_bytes); | |
5107 | local.total_bytes = local.size; | |
5108 | } | |
5109 | } | |
5110 | ||
5111 | return local.total_bytes; | |
5243fbff | 5112 | } |
649d8da6 | 5113 | |
7578526f | 5114 | /* Mark DECL as weak. */ |
5115 | ||
5116 | static void | |
3180a54f | 5117 | mark_weak (tree decl) |
7578526f | 5118 | { |
5119 | DECL_WEAK (decl) = 1; | |
5120 | ||
5121 | if (DECL_RTL_SET_P (decl) | |
e16ceb8e | 5122 | && MEM_P (DECL_RTL (decl)) |
7578526f | 5123 | && XEXP (DECL_RTL (decl), 0) |
5124 | && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF) | |
5125 | SYMBOL_REF_WEAK (XEXP (DECL_RTL (decl), 0)) = 1; | |
5126 | } | |
6c34d0c2 | 5127 | |
296c463e | 5128 | /* Merge weak status between NEWDECL and OLDDECL. */ |
5129 | ||
5130 | void | |
3180a54f | 5131 | merge_weak (tree newdecl, tree olddecl) |
296c463e | 5132 | { |
296c463e | 5133 | if (DECL_WEAK (newdecl) == DECL_WEAK (olddecl)) |
9db59310 | 5134 | { |
5135 | if (DECL_WEAK (newdecl) && SUPPORTS_WEAK) | |
5136 | { | |
5137 | tree *pwd; | |
5138 | /* We put the NEWDECL on the weak_decls list at some point | |
5139 | and OLDDECL as well. Keep just OLDDECL on the list. */ | |
5140 | for (pwd = &weak_decls; *pwd; pwd = &TREE_CHAIN (*pwd)) | |
5141 | if (TREE_VALUE (*pwd) == newdecl) | |
5142 | { | |
5143 | *pwd = TREE_CHAIN (*pwd); | |
5144 | break; | |
5145 | } | |
5146 | } | |
5147 | return; | |
5148 | } | |
296c463e | 5149 | |
7578526f | 5150 | if (DECL_WEAK (newdecl)) |
5151 | { | |
5152 | tree wd; | |
6c34d0c2 | 5153 | |
7578526f | 5154 | /* NEWDECL is weak, but OLDDECL is not. */ |
5155 | ||
5156 | /* If we already output the OLDDECL, we're in trouble; we can't | |
8f05ee5c | 5157 | go back and make it weak. This error cannot be caught in |
7578526f | 5158 | declare_weak because the NEWDECL and OLDDECL was not yet |
5159 | been merged; therefore, TREE_ASM_WRITTEN was not set. */ | |
b0a9f80a | 5160 | if (TREE_ASM_WRITTEN (olddecl)) |
3cf8b391 | 5161 | error ("weak declaration of %q+D must precede definition", |
5162 | newdecl); | |
b0a9f80a | 5163 | |
5164 | /* If we've already generated rtl referencing OLDDECL, we may | |
5165 | have done so in a way that will not function properly with | |
5166 | a weak symbol. */ | |
5167 | else if (TREE_USED (olddecl) | |
83f61433 | 5168 | && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (olddecl))) |
3cf8b391 | 5169 | warning (0, "weak declaration of %q+D after first use results " |
5170 | "in unspecified behavior", newdecl); | |
b0a9f80a | 5171 | |
7578526f | 5172 | if (SUPPORTS_WEAK) |
5173 | { | |
5174 | /* We put the NEWDECL on the weak_decls list at some point. | |
5175 | Replace it with the OLDDECL. */ | |
5176 | for (wd = weak_decls; wd; wd = TREE_CHAIN (wd)) | |
5177 | if (TREE_VALUE (wd) == newdecl) | |
5178 | { | |
5179 | TREE_VALUE (wd) = olddecl; | |
5180 | break; | |
5181 | } | |
5182 | /* We may not find the entry on the list. If NEWDECL is a | |
5183 | weak alias, then we will have already called | |
5184 | globalize_decl to remove the entry; in that case, we do | |
5185 | not need to do anything. */ | |
5186 | } | |
296c463e | 5187 | |
7578526f | 5188 | /* Make the OLDDECL weak; it's OLDDECL that we'll be keeping. */ |
5189 | mark_weak (olddecl); | |
5190 | } | |
5191 | else | |
5192 | /* OLDDECL was weak, but NEWDECL was not explicitly marked as | |
5193 | weak. Just update NEWDECL to indicate that it's weak too. */ | |
5194 | mark_weak (newdecl); | |
296c463e | 5195 | } |
5196 | ||
df1c8607 | 5197 | /* Declare DECL to be a weak symbol. */ |
5198 | ||
5199 | void | |
3180a54f | 5200 | declare_weak (tree decl) |
df1c8607 | 5201 | { |
5202 | if (! TREE_PUBLIC (decl)) | |
3cf8b391 | 5203 | error ("weak declaration of %q+D must be public", decl); |
296c463e | 5204 | else if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) |
3cf8b391 | 5205 | error ("weak declaration of %q+D must precede definition", decl); |
d36229a0 | 5206 | else if (!SUPPORTS_WEAK) |
3cf8b391 | 5207 | warning (0, "weak declaration of %q+D not supported", decl); |
2f1537d1 | 5208 | |
7578526f | 5209 | mark_weak (decl); |
df1c8607 | 5210 | } |
5211 | ||
f4a30bd7 | 5212 | static void |
5213 | weak_finish_1 (tree decl) | |
df1c8607 | 5214 | { |
805e22b2 | 5215 | #if defined (ASM_WEAKEN_DECL) || defined (ASM_WEAKEN_LABEL) |
f4a30bd7 | 5216 | const char *const name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
805e22b2 | 5217 | #endif |
5626f4cd | 5218 | |
f4a30bd7 | 5219 | if (! TREE_USED (decl)) |
5220 | return; | |
5221 | ||
ee0125fb | 5222 | #ifdef ASM_WEAKEN_DECL |
f4a30bd7 | 5223 | ASM_WEAKEN_DECL (asm_out_file, decl, name, NULL); |
2f1537d1 | 5224 | #else |
5225 | #ifdef ASM_WEAKEN_LABEL | |
f4a30bd7 | 5226 | ASM_WEAKEN_LABEL (asm_out_file, name); |
5626f4cd | 5227 | #else |
5228 | #ifdef ASM_OUTPUT_WEAK_ALIAS | |
f4a30bd7 | 5229 | { |
5230 | static bool warn_once = 0; | |
5231 | if (! warn_once) | |
5232 | { | |
5233 | warning (0, "only weak aliases are supported in this configuration"); | |
5234 | warn_once = 1; | |
5235 | } | |
5236 | return; | |
5237 | } | |
5238 | #endif | |
2f1537d1 | 5239 | #endif |
ee0125fb | 5240 | #endif |
f4a30bd7 | 5241 | } |
5242 | ||
5243 | /* This TREE_LIST contains weakref targets. */ | |
5244 | ||
5245 | static GTY(()) tree weakref_targets; | |
5246 | ||
5247 | /* Forward declaration. */ | |
5248 | static tree find_decl_and_mark_needed (tree decl, tree target); | |
5249 | ||
5250 | /* Emit any pending weak declarations. */ | |
5251 | ||
5252 | void | |
5253 | weak_finish (void) | |
5254 | { | |
5255 | tree t; | |
5256 | ||
5257 | for (t = weakref_targets; t; t = TREE_CHAIN (t)) | |
5258 | { | |
5259 | tree alias_decl = TREE_PURPOSE (t); | |
5260 | tree target = ultimate_transparent_alias_target (&TREE_VALUE (t)); | |
5261 | ||
5262 | if (! TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias_decl))) | |
5263 | /* Remove alias_decl from the weak list, but leave entries for | |
5264 | the target alone. */ | |
5265 | target = NULL_TREE; | |
5266 | #ifndef ASM_OUTPUT_WEAKREF | |
5267 | else if (! TREE_SYMBOL_REFERENCED (target)) | |
5268 | { | |
b0988db1 | 5269 | /* Use ASM_WEAKEN_LABEL only if ASM_WEAKEN_DECL is not |
8f05ee5c | 5270 | defined, otherwise we and weak_finish_1 would use |
b0988db1 | 5271 | different macros. */ |
5272 | # if defined ASM_WEAKEN_LABEL && ! defined ASM_WEAKEN_DECL | |
f4a30bd7 | 5273 | ASM_WEAKEN_LABEL (asm_out_file, IDENTIFIER_POINTER (target)); |
5274 | # else | |
5275 | tree decl = find_decl_and_mark_needed (alias_decl, target); | |
5276 | ||
5277 | if (! decl) | |
5278 | { | |
e60a6f7b | 5279 | decl = build_decl (DECL_SOURCE_LOCATION (alias_decl), |
5280 | TREE_CODE (alias_decl), target, | |
f4a30bd7 | 5281 | TREE_TYPE (alias_decl)); |
5282 | ||
5283 | DECL_EXTERNAL (decl) = 1; | |
5284 | TREE_PUBLIC (decl) = 1; | |
5285 | DECL_ARTIFICIAL (decl) = 1; | |
5286 | TREE_NOTHROW (decl) = TREE_NOTHROW (alias_decl); | |
5287 | TREE_USED (decl) = 1; | |
5288 | } | |
5289 | ||
5290 | weak_finish_1 (decl); | |
5291 | # endif | |
5292 | } | |
2f1537d1 | 5293 | #endif |
f4a30bd7 | 5294 | |
5295 | { | |
5296 | tree *p; | |
5297 | tree t2; | |
5298 | ||
5299 | /* Remove the alias and the target from the pending weak list | |
5300 | so that we do not emit any .weak directives for the former, | |
5301 | nor multiple .weak directives for the latter. */ | |
5302 | for (p = &weak_decls; (t2 = *p) ; ) | |
5303 | { | |
5304 | if (TREE_VALUE (t2) == alias_decl | |
5305 | || target == DECL_ASSEMBLER_NAME (TREE_VALUE (t2))) | |
5306 | *p = TREE_CHAIN (t2); | |
5307 | else | |
5308 | p = &TREE_CHAIN (t2); | |
5309 | } | |
5310 | ||
5311 | /* Remove other weakrefs to the same target, to speed things up. */ | |
5312 | for (p = &TREE_CHAIN (t); (t2 = *p) ; ) | |
5313 | { | |
5314 | if (target == ultimate_transparent_alias_target (&TREE_VALUE (t2))) | |
5315 | *p = TREE_CHAIN (t2); | |
5316 | else | |
5317 | p = &TREE_CHAIN (t2); | |
5318 | } | |
5319 | } | |
5320 | } | |
5321 | ||
5322 | for (t = weak_decls; t; t = TREE_CHAIN (t)) | |
5323 | { | |
5324 | tree decl = TREE_VALUE (t); | |
5325 | ||
5326 | weak_finish_1 (decl); | |
df1c8607 | 5327 | } |
df1c8607 | 5328 | } |
2f1537d1 | 5329 | |
1fbd58a2 | 5330 | /* Emit the assembly bits to indicate that DECL is globally visible. */ |
5331 | ||
5332 | static void | |
3180a54f | 5333 | globalize_decl (tree decl) |
1fbd58a2 | 5334 | { |
1fbd58a2 | 5335 | |
5336 | #if defined (ASM_WEAKEN_LABEL) || defined (ASM_WEAKEN_DECL) | |
5337 | if (DECL_WEAK (decl)) | |
5338 | { | |
9afff52d | 5339 | const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); |
5626f4cd | 5340 | tree *p, t; |
5341 | ||
1fbd58a2 | 5342 | #ifdef ASM_WEAKEN_DECL |
5343 | ASM_WEAKEN_DECL (asm_out_file, decl, name, 0); | |
5344 | #else | |
5345 | ASM_WEAKEN_LABEL (asm_out_file, name); | |
5346 | #endif | |
5626f4cd | 5347 | |
1fbd58a2 | 5348 | /* Remove this function from the pending weak list so that |
5349 | we do not emit multiple .weak directives for it. */ | |
f93b586b | 5350 | for (p = &weak_decls; (t = *p) ; ) |
5351 | { | |
5352 | if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))) | |
5626f4cd | 5353 | *p = TREE_CHAIN (t); |
f93b586b | 5354 | else |
5355 | p = &TREE_CHAIN (t); | |
5356 | } | |
f4a30bd7 | 5357 | |
9bbaa634 | 5358 | /* Remove weakrefs to the same target from the pending weakref |
5359 | list, for the same reason. */ | |
5360 | for (p = &weakref_targets; (t = *p) ; ) | |
5361 | { | |
5362 | if (DECL_ASSEMBLER_NAME (decl) | |
5363 | == ultimate_transparent_alias_target (&TREE_VALUE (t))) | |
5364 | *p = TREE_CHAIN (t); | |
5365 | else | |
5366 | p = &TREE_CHAIN (t); | |
5367 | } | |
f4a30bd7 | 5368 | |
1fbd58a2 | 5369 | return; |
5370 | } | |
1fbd58a2 | 5371 | #endif |
5626f4cd | 5372 | |
9afff52d | 5373 | targetm.asm_out.globalize_decl_name (asm_out_file, decl); |
1fbd58a2 | 5374 | } |
5375 | ||
d7401838 | 5376 | /* We have to be able to tell cgraph about the needed-ness of the target |
5377 | of an alias. This requires that the decl have been defined. Aliases | |
06b27565 | 5378 | that precede their definition have to be queued for later processing. */ |
d7401838 | 5379 | |
fb1e4f4a | 5380 | typedef struct GTY(()) alias_pair { |
137900fa | 5381 | tree decl; |
5382 | tree target; | |
046bfc77 | 5383 | } alias_pair; |
137900fa | 5384 | |
5385 | /* Define gc'd vector type. */ | |
046bfc77 | 5386 | DEF_VEC_O(alias_pair); |
5387 | DEF_VEC_ALLOC_O(alias_pair,gc); | |
137900fa | 5388 | |
046bfc77 | 5389 | static GTY(()) VEC(alias_pair,gc) *alias_pairs; |
137900fa | 5390 | |
d7401838 | 5391 | /* Given an assembly name, find the decl it is associated with. At the |
5392 | same time, mark it needed for cgraph. */ | |
5393 | ||
5394 | static tree | |
5395 | find_decl_and_mark_needed (tree decl, tree target) | |
5396 | { | |
5397 | struct cgraph_node *fnode = NULL; | |
1d416bd7 | 5398 | struct varpool_node *vnode = NULL; |
d7401838 | 5399 | |
279cd732 | 5400 | if (TREE_CODE (decl) == FUNCTION_DECL) |
d7401838 | 5401 | { |
279cd732 | 5402 | fnode = cgraph_node_for_asm (target); |
5403 | if (fnode == NULL) | |
1d416bd7 | 5404 | vnode = varpool_node_for_asm (target); |
279cd732 | 5405 | } |
5406 | else | |
5407 | { | |
1d416bd7 | 5408 | vnode = varpool_node_for_asm (target); |
279cd732 | 5409 | if (vnode == NULL) |
5410 | fnode = cgraph_node_for_asm (target); | |
d7401838 | 5411 | } |
5412 | ||
5413 | if (fnode) | |
5414 | { | |
279cd732 | 5415 | /* We can't mark function nodes as used after cgraph global info |
5416 | is finished. This wouldn't generally be necessary, but C++ | |
5417 | virtual table thunks are introduced late in the game and | |
5418 | might seem like they need marking, although in fact they | |
5419 | don't. */ | |
5420 | if (! cgraph_global_info_ready) | |
5421 | cgraph_mark_needed_node (fnode); | |
d7401838 | 5422 | return fnode->decl; |
5423 | } | |
5424 | else if (vnode) | |
5425 | { | |
1d416bd7 | 5426 | varpool_mark_needed_node (vnode); |
d7401838 | 5427 | return vnode->decl; |
5428 | } | |
b215c058 | 5429 | else |
d7401838 | 5430 | return NULL_TREE; |
5431 | } | |
137900fa | 5432 | |
40d475ee | 5433 | /* Output the assembler code for a define (equate) using ASM_OUTPUT_DEF |
5434 | or ASM_OUTPUT_DEF_FROM_DECLS. The function defines the symbol whose | |
5435 | tree node is DECL to have the value of the tree node TARGET. */ | |
5436 | ||
137900fa | 5437 | static void |
f4a30bd7 | 5438 | do_assemble_alias (tree decl, tree target) |
137900fa | 5439 | { |
ea10cf3d | 5440 | if (TREE_ASM_WRITTEN (decl)) |
5441 | return; | |
5442 | ||
d7401838 | 5443 | TREE_ASM_WRITTEN (decl) = 1; |
5444 | TREE_ASM_WRITTEN (DECL_ASSEMBLER_NAME (decl)) = 1; | |
5445 | ||
f4a30bd7 | 5446 | if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))) |
5447 | { | |
5448 | ultimate_transparent_alias_target (&target); | |
5449 | ||
9dda1f80 | 5450 | if (!targetm.have_tls |
5451 | && TREE_CODE (decl) == VAR_DECL | |
5452 | && DECL_THREAD_LOCAL_P (decl)) | |
5453 | { | |
5454 | decl = emutls_decl (decl); | |
5455 | target = get_emutls_object_name (target); | |
5456 | } | |
5457 | ||
f4a30bd7 | 5458 | if (!TREE_SYMBOL_REFERENCED (target)) |
5459 | weakref_targets = tree_cons (decl, target, weakref_targets); | |
5460 | ||
5461 | #ifdef ASM_OUTPUT_WEAKREF | |
b0988db1 | 5462 | ASM_OUTPUT_WEAKREF (asm_out_file, decl, |
f4a30bd7 | 5463 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), |
5464 | IDENTIFIER_POINTER (target)); | |
5465 | #else | |
5466 | if (!SUPPORTS_WEAK) | |
5467 | { | |
712d2297 | 5468 | error_at (DECL_SOURCE_LOCATION (decl), |
5469 | "weakref is not supported in this configuration"); | |
f4a30bd7 | 5470 | return; |
5471 | } | |
5472 | #endif | |
5473 | return; | |
5474 | } | |
5475 | ||
9dda1f80 | 5476 | if (!targetm.have_tls |
5477 | && TREE_CODE (decl) == VAR_DECL | |
5478 | && DECL_THREAD_LOCAL_P (decl)) | |
5479 | { | |
5480 | decl = emutls_decl (decl); | |
5481 | target = get_emutls_object_name (target); | |
5482 | } | |
5483 | ||
d7401838 | 5484 | #ifdef ASM_OUTPUT_DEF |
5485 | /* Make name accessible from other files, if appropriate. */ | |
5486 | ||
5487 | if (TREE_PUBLIC (decl)) | |
5488 | { | |
5489 | globalize_decl (decl); | |
5490 | maybe_assemble_visibility (decl); | |
5491 | } | |
5492 | ||
5493 | # ifdef ASM_OUTPUT_DEF_FROM_DECLS | |
137900fa | 5494 | ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target); |
d7401838 | 5495 | # else |
137900fa | 5496 | ASM_OUTPUT_DEF (asm_out_file, |
5497 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), | |
5498 | IDENTIFIER_POINTER (target)); | |
d7401838 | 5499 | # endif |
5500 | #elif defined (ASM_OUTPUT_WEAK_ALIAS) || defined (ASM_WEAKEN_DECL) | |
5501 | { | |
5502 | const char *name; | |
5503 | tree *p, t; | |
5504 | ||
5505 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
5506 | # ifdef ASM_WEAKEN_DECL | |
5507 | ASM_WEAKEN_DECL (asm_out_file, decl, name, IDENTIFIER_POINTER (target)); | |
5508 | # else | |
5509 | ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target)); | |
5510 | # endif | |
5511 | /* Remove this function from the pending weak list so that | |
5512 | we do not emit multiple .weak directives for it. */ | |
5513 | for (p = &weak_decls; (t = *p) ; ) | |
5514 | if (DECL_ASSEMBLER_NAME (decl) == DECL_ASSEMBLER_NAME (TREE_VALUE (t))) | |
5515 | *p = TREE_CHAIN (t); | |
5516 | else | |
5517 | p = &TREE_CHAIN (t); | |
f4a30bd7 | 5518 | |
5519 | /* Remove weakrefs to the same target from the pending weakref | |
5520 | list, for the same reason. */ | |
5521 | for (p = &weakref_targets; (t = *p) ; ) | |
5522 | { | |
5523 | if (DECL_ASSEMBLER_NAME (decl) | |
5524 | == ultimate_transparent_alias_target (&TREE_VALUE (t))) | |
5525 | *p = TREE_CHAIN (t); | |
5526 | else | |
5527 | p = &TREE_CHAIN (t); | |
5528 | } | |
d7401838 | 5529 | } |
137900fa | 5530 | #endif |
5531 | } | |
137900fa | 5532 | |
d7401838 | 5533 | /* First pass of completing pending aliases. Make sure that cgraph knows |
5534 | which symbols will be required. */ | |
137900fa | 5535 | |
5536 | void | |
d7401838 | 5537 | finish_aliases_1 (void) |
137900fa | 5538 | { |
137900fa | 5539 | unsigned i; |
046bfc77 | 5540 | alias_pair *p; |
137900fa | 5541 | |
d7401838 | 5542 | for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++) |
5543 | { | |
5544 | tree target_decl; | |
5545 | ||
5546 | target_decl = find_decl_and_mark_needed (p->decl, p->target); | |
5547 | if (target_decl == NULL) | |
f4a30bd7 | 5548 | { |
5549 | if (! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl))) | |
27746e01 | 5550 | error ("%q+D aliased to undefined symbol %qE", |
5551 | p->decl, p->target); | |
f4a30bd7 | 5552 | } |
5553 | else if (DECL_EXTERNAL (target_decl) | |
5554 | && ! lookup_attribute ("weakref", DECL_ATTRIBUTES (p->decl))) | |
27746e01 | 5555 | error ("%q+D aliased to external symbol %qE", |
5556 | p->decl, p->target); | |
d7401838 | 5557 | } |
5558 | } | |
137900fa | 5559 | |
d7401838 | 5560 | /* Second pass of completing pending aliases. Emit the actual assembly. |
5561 | This happens at the end of compilation and thus it is assured that the | |
5562 | target symbol has been emitted. */ | |
5563 | ||
5564 | void | |
5565 | finish_aliases_2 (void) | |
5566 | { | |
5567 | unsigned i; | |
046bfc77 | 5568 | alias_pair *p; |
d7401838 | 5569 | |
5570 | for (i = 0; VEC_iterate (alias_pair, alias_pairs, i, p); i++) | |
5571 | do_assemble_alias (p->decl, p->target); | |
5572 | ||
046bfc77 | 5573 | VEC_truncate (alias_pair, alias_pairs, 0); |
137900fa | 5574 | } |
5575 | ||
2f1537d1 | 5576 | /* Emit an assembler directive to make the symbol for DECL an alias to |
5577 | the symbol for TARGET. */ | |
df1c8607 | 5578 | |
5579 | void | |
8bc09a74 | 5580 | assemble_alias (tree decl, tree target) |
df1c8607 | 5581 | { |
d7401838 | 5582 | tree target_decl; |
f4a30bd7 | 5583 | bool is_weakref = false; |
df1c8607 | 5584 | |
f4a30bd7 | 5585 | if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))) |
5586 | { | |
5587 | tree alias = DECL_ASSEMBLER_NAME (decl); | |
5588 | ||
5589 | is_weakref = true; | |
5590 | ||
5591 | ultimate_transparent_alias_target (&target); | |
5592 | ||
5593 | if (alias == target) | |
d77500a3 | 5594 | error ("weakref %q+D ultimately targets itself", decl); |
f4a30bd7 | 5595 | else |
5596 | { | |
5597 | #ifndef ASM_OUTPUT_WEAKREF | |
5598 | IDENTIFIER_TRANSPARENT_ALIAS (alias) = 1; | |
5599 | TREE_CHAIN (alias) = target; | |
5600 | #endif | |
5601 | } | |
0a3ecdc1 | 5602 | if (TREE_PUBLIC (decl)) |
5603 | error ("weakref %q+D must have static linkage", decl); | |
f4a30bd7 | 5604 | } |
5605 | else | |
5606 | { | |
d7401838 | 5607 | #if !defined (ASM_OUTPUT_DEF) |
5608 | # if !defined(ASM_OUTPUT_WEAK_ALIAS) && !defined (ASM_WEAKEN_DECL) | |
712d2297 | 5609 | error_at (DECL_SOURCE_LOCATION (decl), |
5610 | "alias definitions not supported in this configuration"); | |
d7401838 | 5611 | return; |
f4a30bd7 | 5612 | # else |
5613 | if (!DECL_WEAK (decl)) | |
5614 | { | |
712d2297 | 5615 | error_at (DECL_SOURCE_LOCATION (decl), |
5616 | "only weak aliases are supported in this configuration"); | |
f4a30bd7 | 5617 | return; |
5618 | } | |
d7401838 | 5619 | # endif |
5620 | #endif | |
f4a30bd7 | 5621 | } |
df1c8607 | 5622 | |
d7401838 | 5623 | /* We must force creation of DECL_RTL for debug info generation, even though |
5624 | we don't use it here. */ | |
5625 | make_decl_rtl (decl); | |
5626 | TREE_USED (decl) = 1; | |
137900fa | 5627 | |
d7401838 | 5628 | /* A quirk of the initial implementation of aliases required that the user |
5629 | add "extern" to all of them. Which is silly, but now historical. Do | |
5630 | note that the symbol is in fact locally defined. */ | |
f4a30bd7 | 5631 | if (! is_weakref) |
5632 | DECL_EXTERNAL (decl) = 0; | |
137900fa | 5633 | |
d7401838 | 5634 | /* Allow aliases to aliases. */ |
5635 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
1d09f0e6 | 5636 | cgraph_node (decl)->alias = true; |
577f0c5d | 5637 | else |
1d416bd7 | 5638 | varpool_node (decl)->alias = true; |
577f0c5d | 5639 | |
d7401838 | 5640 | /* If the target has already been emitted, we don't have to queue the |
8f05ee5c | 5641 | alias. This saves a tad of memory. */ |
6329636b | 5642 | if (cgraph_global_info_ready) |
28485874 | 5643 | target_decl = find_decl_and_mark_needed (decl, target); |
5644 | else | |
5645 | target_decl= NULL; | |
d7401838 | 5646 | if (target_decl && TREE_ASM_WRITTEN (target_decl)) |
5647 | do_assemble_alias (decl, target); | |
5648 | else | |
8bc09a74 | 5649 | { |
046bfc77 | 5650 | alias_pair *p = VEC_safe_push (alias_pair, gc, alias_pairs, NULL); |
d7401838 | 5651 | p->decl = decl; |
5652 | p->target = target; | |
8bc09a74 | 5653 | } |
df1c8607 | 5654 | } |
2f6cfdb5 | 5655 | |
b4cf9ec1 | 5656 | /* Emit an assembler directive to set symbol for DECL visibility to |
8cf34b34 | 5657 | the visibility type VIS, which must not be VISIBILITY_DEFAULT. */ |
b4cf9ec1 | 5658 | |
5659 | void | |
3180a54f | 5660 | default_assemble_visibility (tree decl, int vis) |
b4cf9ec1 | 5661 | { |
8cf34b34 | 5662 | static const char * const visibility_types[] = { |
4a2849cb | 5663 | NULL, "protected", "hidden", "internal" |
8cf34b34 | 5664 | }; |
5665 | ||
5666 | const char *name, *type; | |
b4cf9ec1 | 5667 | |
8faeb318 | 5668 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); |
8cf34b34 | 5669 | type = visibility_types[vis]; |
b4cf9ec1 | 5670 | |
5671 | #ifdef HAVE_GAS_HIDDEN | |
55e9fda5 | 5672 | fprintf (asm_out_file, "\t.%s\t", type); |
5673 | assemble_name (asm_out_file, name); | |
5674 | fprintf (asm_out_file, "\n"); | |
b4cf9ec1 | 5675 | #else |
9b2d6d13 | 5676 | warning (OPT_Wattributes, "visibility attribute not supported " |
5677 | "in this configuration; ignored"); | |
b4cf9ec1 | 5678 | #endif |
5679 | } | |
5680 | ||
01694f08 | 5681 | /* A helper function to call assemble_visibility when needed for a decl. */ |
5682 | ||
44b23e05 | 5683 | int |
3180a54f | 5684 | maybe_assemble_visibility (tree decl) |
01694f08 | 5685 | { |
9c40570a | 5686 | enum symbol_visibility vis = DECL_VISIBILITY (decl); |
8cf34b34 | 5687 | |
5688 | if (vis != VISIBILITY_DEFAULT) | |
44b23e05 | 5689 | { |
5690 | targetm.asm_out.visibility (decl, vis); | |
5691 | return 1; | |
5692 | } | |
5693 | else | |
5694 | return 0; | |
01694f08 | 5695 | } |
5696 | ||
2f6cfdb5 | 5697 | /* Returns 1 if the target configuration supports defining public symbols |
5698 | so that one of them will be chosen at link time instead of generating a | |
5699 | multiply-defined symbol error, whether through the use of weak symbols or | |
5700 | a target-specific mechanism for having duplicates discarded. */ | |
5701 | ||
5702 | int | |
3180a54f | 5703 | supports_one_only (void) |
2f6cfdb5 | 5704 | { |
5705 | if (SUPPORTS_ONE_ONLY) | |
5706 | return 1; | |
5707 | return SUPPORTS_WEAK; | |
5708 | } | |
5709 | ||
5710 | /* Set up DECL as a public symbol that can be defined in multiple | |
5711 | translation units without generating a linker error. */ | |
5712 | ||
5713 | void | |
ecd88073 | 5714 | make_decl_one_only (tree decl, tree comdat_group) |
2f6cfdb5 | 5715 | { |
22167fd5 | 5716 | gcc_assert (TREE_CODE (decl) == VAR_DECL |
5717 | || TREE_CODE (decl) == FUNCTION_DECL); | |
2f6cfdb5 | 5718 | |
5719 | TREE_PUBLIC (decl) = 1; | |
5720 | ||
2f9fc8ef | 5721 | if (SUPPORTS_ONE_ONLY) |
2f6cfdb5 | 5722 | { |
5723 | #ifdef MAKE_DECL_ONE_ONLY | |
5724 | MAKE_DECL_ONE_ONLY (decl); | |
5725 | #endif | |
ecd88073 | 5726 | DECL_COMDAT_GROUP (decl) = comdat_group; |
2f6cfdb5 | 5727 | } |
2f9fc8ef | 5728 | else if (TREE_CODE (decl) == VAR_DECL |
5729 | && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)) | |
5730 | DECL_COMMON (decl) = 1; | |
2f6cfdb5 | 5731 | else |
22167fd5 | 5732 | { |
5733 | gcc_assert (SUPPORTS_WEAK); | |
5734 | DECL_WEAK (decl) = 1; | |
5735 | } | |
2f6cfdb5 | 5736 | } |
2c8daaf1 | 5737 | |
5738 | void | |
3180a54f | 5739 | init_varasm_once (void) |
2c8daaf1 | 5740 | { |
2f14b1f9 | 5741 | section_htab = htab_create_ggc (31, section_entry_hash, |
5742 | section_entry_eq, NULL); | |
f2d0e9f1 | 5743 | object_block_htab = htab_create_ggc (31, object_block_entry_hash, |
5744 | object_block_entry_eq, NULL); | |
364bde6b | 5745 | const_desc_htab = htab_create_ggc (1009, const_desc_hash, |
5746 | const_desc_eq, NULL); | |
29a0ebee | 5747 | |
ebde4c17 | 5748 | const_alias_set = new_alias_set (); |
2dbdc48e | 5749 | shared_constant_pool = create_constant_pool (); |
2f14b1f9 | 5750 | |
5751 | #ifdef TEXT_SECTION_ASM_OP | |
5752 | text_section = get_unnamed_section (SECTION_CODE, output_section_asm_op, | |
5753 | TEXT_SECTION_ASM_OP); | |
5754 | #endif | |
5755 | ||
5756 | #ifdef DATA_SECTION_ASM_OP | |
5757 | data_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op, | |
5758 | DATA_SECTION_ASM_OP); | |
5759 | #endif | |
5760 | ||
5761 | #ifdef SDATA_SECTION_ASM_OP | |
5762 | sdata_section = get_unnamed_section (SECTION_WRITE, output_section_asm_op, | |
5763 | SDATA_SECTION_ASM_OP); | |
5764 | #endif | |
5765 | ||
5766 | #ifdef READONLY_DATA_SECTION_ASM_OP | |
5767 | readonly_data_section = get_unnamed_section (0, output_section_asm_op, | |
5768 | READONLY_DATA_SECTION_ASM_OP); | |
5769 | #endif | |
5770 | ||
5771 | #ifdef CTORS_SECTION_ASM_OP | |
5772 | ctors_section = get_unnamed_section (0, output_section_asm_op, | |
5773 | CTORS_SECTION_ASM_OP); | |
5774 | #endif | |
5775 | ||
5776 | #ifdef DTORS_SECTION_ASM_OP | |
5777 | dtors_section = get_unnamed_section (0, output_section_asm_op, | |
5778 | DTORS_SECTION_ASM_OP); | |
5779 | #endif | |
5780 | ||
5781 | #ifdef BSS_SECTION_ASM_OP | |
5782 | bss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS, | |
5783 | output_section_asm_op, | |
5784 | BSS_SECTION_ASM_OP); | |
5785 | #endif | |
5786 | ||
5787 | #ifdef SBSS_SECTION_ASM_OP | |
5788 | sbss_section = get_unnamed_section (SECTION_WRITE | SECTION_BSS, | |
5789 | output_section_asm_op, | |
5790 | SBSS_SECTION_ASM_OP); | |
5791 | #endif | |
5792 | ||
102e3995 | 5793 | tls_comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS |
5794 | | SECTION_COMMON, emit_tls_common); | |
5795 | lcomm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS | |
5796 | | SECTION_COMMON, emit_local); | |
5797 | comm_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS | |
5798 | | SECTION_COMMON, emit_common); | |
5799 | ||
5800 | #if defined ASM_OUTPUT_ALIGNED_BSS || defined ASM_OUTPUT_BSS | |
5801 | bss_noswitch_section = get_noswitch_section (SECTION_WRITE | SECTION_BSS, | |
5802 | emit_bss); | |
5803 | #endif | |
5804 | ||
2f14b1f9 | 5805 | targetm.asm_out.init_sections (); |
5806 | ||
5807 | if (readonly_data_section == NULL) | |
5808 | readonly_data_section = text_section; | |
2c8daaf1 | 5809 | } |
2cb4ac60 | 5810 | |
1b53eb20 | 5811 | enum tls_model |
a9f1838b | 5812 | decl_default_tls_model (const_tree decl) |
24dfead4 | 5813 | { |
5814 | enum tls_model kind; | |
24dfead4 | 5815 | bool is_local; |
5816 | ||
883b2e73 | 5817 | is_local = targetm.binds_local_p (decl); |
c0b0db27 | 5818 | if (!flag_shlib) |
24dfead4 | 5819 | { |
5820 | if (is_local) | |
5821 | kind = TLS_MODEL_LOCAL_EXEC; | |
5822 | else | |
5823 | kind = TLS_MODEL_INITIAL_EXEC; | |
5824 | } | |
1b53eb20 | 5825 | |
24dfead4 | 5826 | /* Local dynamic is inefficient when we're not combining the |
5827 | parts of the address. */ | |
5828 | else if (optimize && is_local) | |
5829 | kind = TLS_MODEL_LOCAL_DYNAMIC; | |
5830 | else | |
5831 | kind = TLS_MODEL_GLOBAL_DYNAMIC; | |
5832 | if (kind < flag_tls_default) | |
5833 | kind = flag_tls_default; | |
5834 | ||
5835 | return kind; | |
5836 | } | |
5837 | ||
2cb4ac60 | 5838 | /* Select a set of attributes for section NAME based on the properties |
5839 | of DECL and whether or not RELOC indicates that DECL's initializer | |
5840 | might contain runtime relocations. | |
5841 | ||
5842 | We make the section read-only and executable for a function decl, | |
29a0ebee | 5843 | read-only for a const data decl, and writable for a non-const data decl. */ |
2cb4ac60 | 5844 | |
5845 | unsigned int | |
3180a54f | 5846 | default_section_type_flags (tree decl, const char *name, int reloc) |
2cb4ac60 | 5847 | { |
2cb4ac60 | 5848 | unsigned int flags; |
2cb4ac60 | 5849 | |
5850 | if (decl && TREE_CODE (decl) == FUNCTION_DECL) | |
5851 | flags = SECTION_CODE; | |
4e151b05 | 5852 | else if (decl && decl_readonly_section (decl, reloc)) |
2cb4ac60 | 5853 | flags = 0; |
4d0e931f | 5854 | else if (current_function_decl |
5855 | && cfun | |
abe32cce | 5856 | && crtl->subsections.unlikely_text_section_name |
5857 | && strcmp (name, crtl->subsections.unlikely_text_section_name) == 0) | |
4f18499c | 5858 | flags = SECTION_CODE; |
b215c058 | 5859 | else if (!decl |
4d0e931f | 5860 | && (!current_function_decl || !cfun) |
5861 | && strcmp (name, UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0) | |
b215c058 | 5862 | flags = SECTION_CODE; |
2cb4ac60 | 5863 | else |
5864 | flags = SECTION_WRITE; | |
5865 | ||
5866 | if (decl && DECL_ONE_ONLY (decl)) | |
5867 | flags |= SECTION_LINKONCE; | |
5868 | ||
1b53eb20 | 5869 | if (decl && TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL_P (decl)) |
1a201dc6 | 5870 | flags |= SECTION_TLS | SECTION_WRITE; |
5871 | ||
2cb4ac60 | 5872 | if (strcmp (name, ".bss") == 0 |
5873 | || strncmp (name, ".bss.", 5) == 0 | |
64717bc5 | 5874 | || strncmp (name, ".gnu.linkonce.b.", 16) == 0 |
5875 | || strcmp (name, ".sbss") == 0 | |
09727e8a | 5876 | || strncmp (name, ".sbss.", 6) == 0 |
5877 | || strncmp (name, ".gnu.linkonce.sb.", 17) == 0) | |
64717bc5 | 5878 | flags |= SECTION_BSS; |
09727e8a | 5879 | |
2a6f0f81 | 5880 | if (strcmp (name, ".tdata") == 0 |
09727e8a | 5881 | || strncmp (name, ".tdata.", 7) == 0 |
5882 | || strncmp (name, ".gnu.linkonce.td.", 17) == 0) | |
2a6f0f81 | 5883 | flags |= SECTION_TLS; |
5884 | ||
09727e8a | 5885 | if (strcmp (name, ".tbss") == 0 |
5886 | || strncmp (name, ".tbss.", 6) == 0 | |
5887 | || strncmp (name, ".gnu.linkonce.tb.", 17) == 0) | |
5888 | flags |= SECTION_TLS | SECTION_BSS; | |
5889 | ||
73062b44 | 5890 | /* These three sections have special ELF types. They are neither |
5891 | SHT_PROGBITS nor SHT_NOBITS, so when changing sections we don't | |
5892 | want to print a section type (@progbits or @nobits). If someone | |
5893 | is silly enough to emit code or TLS variables to one of these | |
5894 | sections, then don't handle them specially. */ | |
5895 | if (!(flags & (SECTION_CODE | SECTION_BSS | SECTION_TLS)) | |
5896 | && (strcmp (name, ".init_array") == 0 | |
5897 | || strcmp (name, ".fini_array") == 0 | |
5898 | || strcmp (name, ".preinit_array") == 0)) | |
5899 | flags |= SECTION_NOTYPE; | |
5900 | ||
2cb4ac60 | 5901 | return flags; |
5902 | } | |
5903 | ||
102e3995 | 5904 | /* Return true if the target supports some form of global BSS, |
5905 | either through bss_noswitch_section, or by selecting a BSS | |
5906 | section in TARGET_ASM_SELECT_SECTION. */ | |
5907 | ||
5908 | bool | |
5909 | have_global_bss_p (void) | |
5910 | { | |
5911 | return bss_noswitch_section || targetm.have_switchable_bss_sections; | |
5912 | } | |
5913 | ||
2cb4ac60 | 5914 | /* Output assembly to switch to section NAME with attribute FLAGS. |
5915 | Four variants for common object file formats. */ | |
5916 | ||
5917 | void | |
3180a54f | 5918 | default_no_named_section (const char *name ATTRIBUTE_UNUSED, |
537cd941 | 5919 | unsigned int flags ATTRIBUTE_UNUSED, |
5920 | tree decl ATTRIBUTE_UNUSED) | |
2cb4ac60 | 5921 | { |
5922 | /* Some object formats don't support named sections at all. The | |
5923 | front-end should already have flagged this as an error. */ | |
22167fd5 | 5924 | gcc_unreachable (); |
2cb4ac60 | 5925 | } |
5926 | ||
5927 | void | |
537cd941 | 5928 | default_elf_asm_named_section (const char *name, unsigned int flags, |
5929 | tree decl ATTRIBUTE_UNUSED) | |
2cb4ac60 | 5930 | { |
bb2821c0 | 5931 | char flagchars[10], *f = flagchars; |
2cb4ac60 | 5932 | |
537cd941 | 5933 | /* If we have already declared this section, we can use an |
5934 | abbreviated form to switch back to it -- unless this section is | |
5935 | part of a COMDAT groups, in which case GAS requires the full | |
5936 | declaration every time. */ | |
2593b9be | 5937 | if (!(HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) |
2f14b1f9 | 5938 | && (flags & SECTION_DECLARED)) |
5cdb6d31 | 5939 | { |
5940 | fprintf (asm_out_file, "\t.section\t%s\n", name); | |
5941 | return; | |
5942 | } | |
5943 | ||
2cb4ac60 | 5944 | if (!(flags & SECTION_DEBUG)) |
5945 | *f++ = 'a'; | |
5946 | if (flags & SECTION_WRITE) | |
5947 | *f++ = 'w'; | |
5948 | if (flags & SECTION_CODE) | |
5949 | *f++ = 'x'; | |
5950 | if (flags & SECTION_SMALL) | |
5951 | *f++ = 's'; | |
bb2821c0 | 5952 | if (flags & SECTION_MERGE) |
5953 | *f++ = 'M'; | |
5954 | if (flags & SECTION_STRINGS) | |
5955 | *f++ = 'S'; | |
2a6f0f81 | 5956 | if (flags & SECTION_TLS) |
5957 | *f++ = 'T'; | |
2593b9be | 5958 | if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) |
537cd941 | 5959 | *f++ = 'G'; |
2cb4ac60 | 5960 | *f = '\0'; |
5961 | ||
73062b44 | 5962 | fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars); |
2cb4ac60 | 5963 | |
73062b44 | 5964 | if (!(flags & SECTION_NOTYPE)) |
5965 | { | |
5966 | const char *type; | |
537cd941 | 5967 | const char *format; |
73062b44 | 5968 | |
5969 | if (flags & SECTION_BSS) | |
5970 | type = "nobits"; | |
5971 | else | |
5972 | type = "progbits"; | |
5973 | ||
537cd941 | 5974 | format = ",@%s"; |
5975 | #ifdef ASM_COMMENT_START | |
5976 | /* On platforms that use "@" as the assembly comment character, | |
5977 | use "%" instead. */ | |
5978 | if (strcmp (ASM_COMMENT_START, "@") == 0) | |
5979 | format = ",%%%s"; | |
5980 | #endif | |
5981 | fprintf (asm_out_file, format, type); | |
73062b44 | 5982 | |
5983 | if (flags & SECTION_ENTSIZE) | |
5984 | fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE); | |
2593b9be | 5985 | if (HAVE_COMDAT_GROUP && (flags & SECTION_LINKONCE)) |
b215c058 | 5986 | fprintf (asm_out_file, ",%s,comdat", |
ecd88073 | 5987 | IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl))); |
73062b44 | 5988 | } |
5989 | ||
5990 | putc ('\n', asm_out_file); | |
2cb4ac60 | 5991 | } |
5992 | ||
5993 | void | |
b215c058 | 5994 | default_coff_asm_named_section (const char *name, unsigned int flags, |
537cd941 | 5995 | tree decl ATTRIBUTE_UNUSED) |
2cb4ac60 | 5996 | { |
5997 | char flagchars[8], *f = flagchars; | |
5998 | ||
5999 | if (flags & SECTION_WRITE) | |
6000 | *f++ = 'w'; | |
6001 | if (flags & SECTION_CODE) | |
6002 | *f++ = 'x'; | |
6003 | *f = '\0'; | |
6004 | ||
6005 | fprintf (asm_out_file, "\t.section\t%s,\"%s\"\n", name, flagchars); | |
6006 | } | |
6007 | ||
6008 | void | |
537cd941 | 6009 | default_pe_asm_named_section (const char *name, unsigned int flags, |
6010 | tree decl) | |
2cb4ac60 | 6011 | { |
537cd941 | 6012 | default_coff_asm_named_section (name, flags, decl); |
2cb4ac60 | 6013 | |
6014 | if (flags & SECTION_LINKONCE) | |
6015 | { | |
6016 | /* Functions may have been compiled at various levels of | |
6017 | optimization so we can't use `same_size' here. | |
6018 | Instead, have the linker pick one. */ | |
6019 | fprintf (asm_out_file, "\t.linkonce %s\n", | |
6020 | (flags & SECTION_CODE ? "discard" : "same_size")); | |
6021 | } | |
6022 | } | |
cef0c6a0 | 6023 | \f |
52470889 | 6024 | /* The lame default section selector. */ |
6025 | ||
2f14b1f9 | 6026 | section * |
3180a54f | 6027 | default_select_section (tree decl, int reloc, |
6028 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
52470889 | 6029 | { |
52470889 | 6030 | if (DECL_P (decl)) |
6031 | { | |
f4111c94 | 6032 | if (decl_readonly_section (decl, reloc)) |
2f14b1f9 | 6033 | return readonly_data_section; |
52470889 | 6034 | } |
6035 | else if (TREE_CODE (decl) == CONSTRUCTOR) | |
6036 | { | |
6037 | if (! ((flag_pic && reloc) | |
6038 | || !TREE_READONLY (decl) | |
6039 | || TREE_SIDE_EFFECTS (decl) | |
6040 | || !TREE_CONSTANT (decl))) | |
2f14b1f9 | 6041 | return readonly_data_section; |
52470889 | 6042 | } |
6043 | else if (TREE_CODE (decl) == STRING_CST) | |
2f14b1f9 | 6044 | return readonly_data_section; |
52470889 | 6045 | else if (! (flag_pic && reloc)) |
2f14b1f9 | 6046 | return readonly_data_section; |
52470889 | 6047 | |
2f14b1f9 | 6048 | return data_section; |
52470889 | 6049 | } |
6050 | ||
52470889 | 6051 | enum section_category |
a9f1838b | 6052 | categorize_decl_for_section (const_tree decl, int reloc) |
52470889 | 6053 | { |
6054 | enum section_category ret; | |
6055 | ||
6056 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
6057 | return SECCAT_TEXT; | |
6058 | else if (TREE_CODE (decl) == STRING_CST) | |
4ee9c684 | 6059 | { |
6060 | if (flag_mudflap) /* or !flag_merge_constants */ | |
6061 | return SECCAT_RODATA; | |
6062 | else | |
6063 | return SECCAT_RODATA_MERGE_STR; | |
6064 | } | |
52470889 | 6065 | else if (TREE_CODE (decl) == VAR_DECL) |
6066 | { | |
102e3995 | 6067 | if (bss_initializer_p (decl)) |
52470889 | 6068 | ret = SECCAT_BSS; |
6069 | else if (! TREE_READONLY (decl) | |
6070 | || TREE_SIDE_EFFECTS (decl) | |
6071 | || ! TREE_CONSTANT (DECL_INITIAL (decl))) | |
6072 | { | |
4e151b05 | 6073 | /* Here the reloc_rw_mask is not testing whether the section should |
6074 | be read-only or not, but whether the dynamic link will have to | |
6075 | do something. If so, we wish to segregate the data in order to | |
6076 | minimize cache misses inside the dynamic linker. */ | |
6077 | if (reloc & targetm.asm_out.reloc_rw_mask ()) | |
6078 | ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL; | |
52470889 | 6079 | else |
6080 | ret = SECCAT_DATA; | |
6081 | } | |
4e151b05 | 6082 | else if (reloc & targetm.asm_out.reloc_rw_mask ()) |
6083 | ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO; | |
98a1d439 | 6084 | else if (reloc || flag_merge_constants < 2) |
52470889 | 6085 | /* C and C++ don't allow different variables to share the same |
6086 | location. -fmerge-all-constants allows even that (at the | |
6087 | expense of not conforming). */ | |
6088 | ret = SECCAT_RODATA; | |
6089 | else if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST) | |
6090 | ret = SECCAT_RODATA_MERGE_STR_INIT; | |
6091 | else | |
6092 | ret = SECCAT_RODATA_MERGE_CONST; | |
6093 | } | |
6094 | else if (TREE_CODE (decl) == CONSTRUCTOR) | |
6095 | { | |
4e151b05 | 6096 | if ((reloc & targetm.asm_out.reloc_rw_mask ()) |
52470889 | 6097 | || TREE_SIDE_EFFECTS (decl) |
6098 | || ! TREE_CONSTANT (decl)) | |
6099 | ret = SECCAT_DATA; | |
6100 | else | |
6101 | ret = SECCAT_RODATA; | |
6102 | } | |
6103 | else | |
6104 | ret = SECCAT_RODATA; | |
6105 | ||
2a6f0f81 | 6106 | /* There are no read-only thread-local sections. */ |
38475469 | 6107 | if (TREE_CODE (decl) == VAR_DECL && DECL_TLS_MODEL (decl)) |
2a6f0f81 | 6108 | { |
38475469 | 6109 | if (DECL_TLS_MODEL (decl) == TLS_MODEL_EMULATED) |
6110 | { | |
6111 | if (DECL_EMUTLS_VAR_P (decl)) | |
6112 | { | |
6113 | if (targetm.emutls.var_section) | |
6114 | ret = SECCAT_EMUTLS_VAR; | |
6115 | } | |
6116 | else | |
6117 | { | |
6118 | if (targetm.emutls.tmpl_prefix) | |
6119 | ret = SECCAT_EMUTLS_TMPL; | |
6120 | } | |
6121 | } | |
e51fd8a5 | 6122 | /* Note that this would be *just* SECCAT_BSS, except that there's |
6123 | no concept of a read-only thread-local-data section. */ | |
38475469 | 6124 | else if (ret == SECCAT_BSS |
6125 | || (flag_zero_initialized_in_bss | |
6126 | && initializer_zerop (DECL_INITIAL (decl)))) | |
2a6f0f81 | 6127 | ret = SECCAT_TBSS; |
6128 | else | |
6129 | ret = SECCAT_TDATA; | |
6130 | } | |
6131 | ||
52470889 | 6132 | /* If the target uses small data sections, select it. */ |
883b2e73 | 6133 | else if (targetm.in_small_data_p (decl)) |
52470889 | 6134 | { |
6135 | if (ret == SECCAT_BSS) | |
6136 | ret = SECCAT_SBSS; | |
9292e3be | 6137 | else if (targetm.have_srodata_section && ret == SECCAT_RODATA) |
6138 | ret = SECCAT_SRODATA; | |
52470889 | 6139 | else |
6140 | ret = SECCAT_SDATA; | |
6141 | } | |
6142 | ||
6143 | return ret; | |
6144 | } | |
6145 | ||
f4111c94 | 6146 | bool |
a9f1838b | 6147 | decl_readonly_section (const_tree decl, int reloc) |
f4111c94 | 6148 | { |
4e151b05 | 6149 | switch (categorize_decl_for_section (decl, reloc)) |
f4111c94 | 6150 | { |
6151 | case SECCAT_RODATA: | |
6152 | case SECCAT_RODATA_MERGE_STR: | |
6153 | case SECCAT_RODATA_MERGE_STR_INIT: | |
6154 | case SECCAT_RODATA_MERGE_CONST: | |
9292e3be | 6155 | case SECCAT_SRODATA: |
f4111c94 | 6156 | return true; |
6157 | break; | |
6158 | default: | |
6159 | return false; | |
6160 | break; | |
6161 | } | |
6162 | } | |
6163 | ||
52470889 | 6164 | /* Select a section based on the above categorization. */ |
6165 | ||
2f14b1f9 | 6166 | section * |
3180a54f | 6167 | default_elf_select_section (tree decl, int reloc, |
6168 | unsigned HOST_WIDE_INT align) | |
fb5a6c4c | 6169 | { |
312f7161 | 6170 | const char *sname; |
4e151b05 | 6171 | switch (categorize_decl_for_section (decl, reloc)) |
52470889 | 6172 | { |
6173 | case SECCAT_TEXT: | |
6174 | /* We're not supposed to be called on FUNCTION_DECLs. */ | |
22167fd5 | 6175 | gcc_unreachable (); |
52470889 | 6176 | case SECCAT_RODATA: |
2f14b1f9 | 6177 | return readonly_data_section; |
52470889 | 6178 | case SECCAT_RODATA_MERGE_STR: |
2f14b1f9 | 6179 | return mergeable_string_section (decl, align, 0); |
52470889 | 6180 | case SECCAT_RODATA_MERGE_STR_INIT: |
2f14b1f9 | 6181 | return mergeable_string_section (DECL_INITIAL (decl), align, 0); |
52470889 | 6182 | case SECCAT_RODATA_MERGE_CONST: |
2f14b1f9 | 6183 | return mergeable_constant_section (DECL_MODE (decl), align, 0); |
9292e3be | 6184 | case SECCAT_SRODATA: |
312f7161 | 6185 | sname = ".sdata2"; |
9292e3be | 6186 | break; |
52470889 | 6187 | case SECCAT_DATA: |
2f14b1f9 | 6188 | return data_section; |
52470889 | 6189 | case SECCAT_DATA_REL: |
312f7161 | 6190 | sname = ".data.rel"; |
52470889 | 6191 | break; |
6192 | case SECCAT_DATA_REL_LOCAL: | |
312f7161 | 6193 | sname = ".data.rel.local"; |
52470889 | 6194 | break; |
6195 | case SECCAT_DATA_REL_RO: | |
312f7161 | 6196 | sname = ".data.rel.ro"; |
52470889 | 6197 | break; |
6198 | case SECCAT_DATA_REL_RO_LOCAL: | |
312f7161 | 6199 | sname = ".data.rel.ro.local"; |
52470889 | 6200 | break; |
6201 | case SECCAT_SDATA: | |
312f7161 | 6202 | sname = ".sdata"; |
52470889 | 6203 | break; |
6204 | case SECCAT_TDATA: | |
312f7161 | 6205 | sname = ".tdata"; |
52470889 | 6206 | break; |
6207 | case SECCAT_BSS: | |
2f14b1f9 | 6208 | if (bss_section) |
6209 | return bss_section; | |
312f7161 | 6210 | sname = ".bss"; |
52470889 | 6211 | break; |
6212 | case SECCAT_SBSS: | |
312f7161 | 6213 | sname = ".sbss"; |
52470889 | 6214 | break; |
6215 | case SECCAT_TBSS: | |
312f7161 | 6216 | sname = ".tbss"; |
52470889 | 6217 | break; |
38475469 | 6218 | case SECCAT_EMUTLS_VAR: |
6219 | sname = targetm.emutls.var_section; | |
6220 | break; | |
6221 | case SECCAT_EMUTLS_TMPL: | |
6222 | sname = targetm.emutls.tmpl_section; | |
6223 | break; | |
52470889 | 6224 | default: |
22167fd5 | 6225 | gcc_unreachable (); |
52470889 | 6226 | } |
312f7161 | 6227 | |
6228 | if (!DECL_P (decl)) | |
6229 | decl = NULL_TREE; | |
2f14b1f9 | 6230 | return get_named_section (decl, sname, reloc); |
52470889 | 6231 | } |
6232 | ||
6c34d0c2 | 6233 | /* Construct a unique section name based on the decl name and the |
52470889 | 6234 | categorization performed above. */ |
6235 | ||
6236 | void | |
3180a54f | 6237 | default_unique_section (tree decl, int reloc) |
52470889 | 6238 | { |
2593b9be | 6239 | /* We only need to use .gnu.linkonce if we don't have COMDAT groups. */ |
6240 | bool one_only = DECL_ONE_ONLY (decl) && !HAVE_COMDAT_GROUP; | |
38475469 | 6241 | const char *prefix, *name, *linkonce; |
52470889 | 6242 | char *string; |
6243 | ||
4e151b05 | 6244 | switch (categorize_decl_for_section (decl, reloc)) |
52470889 | 6245 | { |
6246 | case SECCAT_TEXT: | |
38475469 | 6247 | prefix = one_only ? ".t" : ".text"; |
52470889 | 6248 | break; |
6249 | case SECCAT_RODATA: | |
6250 | case SECCAT_RODATA_MERGE_STR: | |
6251 | case SECCAT_RODATA_MERGE_STR_INIT: | |
6252 | case SECCAT_RODATA_MERGE_CONST: | |
38475469 | 6253 | prefix = one_only ? ".r" : ".rodata"; |
52470889 | 6254 | break; |
9292e3be | 6255 | case SECCAT_SRODATA: |
38475469 | 6256 | prefix = one_only ? ".s2" : ".sdata2"; |
9292e3be | 6257 | break; |
52470889 | 6258 | case SECCAT_DATA: |
38475469 | 6259 | prefix = one_only ? ".d" : ".data"; |
3ec5e42b | 6260 | break; |
52470889 | 6261 | case SECCAT_DATA_REL: |
38475469 | 6262 | prefix = one_only ? ".d.rel" : ".data.rel"; |
3ec5e42b | 6263 | break; |
52470889 | 6264 | case SECCAT_DATA_REL_LOCAL: |
38475469 | 6265 | prefix = one_only ? ".d.rel.local" : ".data.rel.local"; |
3ec5e42b | 6266 | break; |
52470889 | 6267 | case SECCAT_DATA_REL_RO: |
38475469 | 6268 | prefix = one_only ? ".d.rel.ro" : ".data.rel.ro"; |
3ec5e42b | 6269 | break; |
52470889 | 6270 | case SECCAT_DATA_REL_RO_LOCAL: |
38475469 | 6271 | prefix = one_only ? ".d.rel.ro.local" : ".data.rel.ro.local"; |
52470889 | 6272 | break; |
6273 | case SECCAT_SDATA: | |
38475469 | 6274 | prefix = one_only ? ".s" : ".sdata"; |
52470889 | 6275 | break; |
6276 | case SECCAT_BSS: | |
38475469 | 6277 | prefix = one_only ? ".b" : ".bss"; |
52470889 | 6278 | break; |
6279 | case SECCAT_SBSS: | |
38475469 | 6280 | prefix = one_only ? ".sb" : ".sbss"; |
52470889 | 6281 | break; |
6282 | case SECCAT_TDATA: | |
38475469 | 6283 | prefix = one_only ? ".td" : ".tdata"; |
1a201dc6 | 6284 | break; |
52470889 | 6285 | case SECCAT_TBSS: |
38475469 | 6286 | prefix = one_only ? ".tb" : ".tbss"; |
6287 | break; | |
6288 | case SECCAT_EMUTLS_VAR: | |
6289 | prefix = targetm.emutls.var_section; | |
6290 | break; | |
6291 | case SECCAT_EMUTLS_TMPL: | |
6292 | prefix = targetm.emutls.tmpl_section; | |
1a201dc6 | 6293 | break; |
52470889 | 6294 | default: |
22167fd5 | 6295 | gcc_unreachable (); |
52470889 | 6296 | } |
52470889 | 6297 | |
6298 | name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)); | |
6fb33aa0 | 6299 | name = targetm.strip_name_encoding (name); |
52470889 | 6300 | |
38475469 | 6301 | /* If we're using one_only, then there needs to be a .gnu.linkonce |
6302 | prefix to the section name. */ | |
6303 | linkonce = one_only ? ".gnu.linkonce" : ""; | |
6304 | ||
6305 | string = ACONCAT ((linkonce, prefix, ".", name, NULL)); | |
52470889 | 6306 | |
38475469 | 6307 | DECL_SECTION_NAME (decl) = build_string (strlen (string), string); |
52470889 | 6308 | } |
bbfbe351 | 6309 | |
4e151b05 | 6310 | /* Like compute_reloc_for_constant, except for an RTX. The return value |
6311 | is a mask for which bit 1 indicates a global relocation, and bit 0 | |
6312 | indicates a local relocation. */ | |
6313 | ||
6314 | static int | |
6315 | compute_reloc_for_rtx_1 (rtx *xp, void *data) | |
6316 | { | |
45ba1503 | 6317 | int *preloc = (int *) data; |
4e151b05 | 6318 | rtx x = *xp; |
6319 | ||
6320 | switch (GET_CODE (x)) | |
6321 | { | |
6322 | case SYMBOL_REF: | |
6323 | *preloc |= SYMBOL_REF_LOCAL_P (x) ? 1 : 2; | |
6324 | break; | |
6325 | case LABEL_REF: | |
6326 | *preloc |= 1; | |
6327 | break; | |
6328 | default: | |
6329 | break; | |
6330 | } | |
6331 | ||
6332 | return 0; | |
6333 | } | |
6334 | ||
6335 | static int | |
6336 | compute_reloc_for_rtx (rtx x) | |
6337 | { | |
6338 | int reloc; | |
6339 | ||
6340 | switch (GET_CODE (x)) | |
6341 | { | |
6342 | case CONST: | |
6343 | case SYMBOL_REF: | |
6344 | case LABEL_REF: | |
6345 | reloc = 0; | |
6346 | for_each_rtx (&x, compute_reloc_for_rtx_1, &reloc); | |
6347 | return reloc; | |
6348 | ||
6349 | default: | |
6350 | return 0; | |
6351 | } | |
6352 | } | |
6353 | ||
2f14b1f9 | 6354 | section * |
3180a54f | 6355 | default_select_rtx_section (enum machine_mode mode ATTRIBUTE_UNUSED, |
6356 | rtx x, | |
6357 | unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED) | |
bbfbe351 | 6358 | { |
4e151b05 | 6359 | if (compute_reloc_for_rtx (x) & targetm.asm_out.reloc_rw_mask ()) |
6360 | return data_section; | |
6361 | else | |
6362 | return readonly_data_section; | |
bbfbe351 | 6363 | } |
6364 | ||
2f14b1f9 | 6365 | section * |
3180a54f | 6366 | default_elf_select_rtx_section (enum machine_mode mode, rtx x, |
6367 | unsigned HOST_WIDE_INT align) | |
bbfbe351 | 6368 | { |
4e151b05 | 6369 | int reloc = compute_reloc_for_rtx (x); |
bbfbe351 | 6370 | |
4e151b05 | 6371 | /* ??? Handle small data here somehow. */ |
bbfbe351 | 6372 | |
4e151b05 | 6373 | if (reloc & targetm.asm_out.reloc_rw_mask ()) |
6374 | { | |
6375 | if (reloc == 1) | |
2f14b1f9 | 6376 | return get_named_section (NULL, ".data.rel.ro.local", 1); |
4e151b05 | 6377 | else |
6378 | return get_named_section (NULL, ".data.rel.ro", 3); | |
6379 | } | |
bbfbe351 | 6380 | |
2f14b1f9 | 6381 | return mergeable_constant_section (mode, align, 0); |
bbfbe351 | 6382 | } |
7b4a38a6 | 6383 | |
001be062 | 6384 | /* Set the generally applicable flags on the SYMBOL_REF for EXP. */ |
6385 | ||
6386 | void | |
3180a54f | 6387 | default_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED) |
001be062 | 6388 | { |
2c129d70 | 6389 | rtx symbol; |
001be062 | 6390 | int flags; |
6391 | ||
001be062 | 6392 | /* Careful not to prod global register variables. */ |
e16ceb8e | 6393 | if (!MEM_P (rtl)) |
001be062 | 6394 | return; |
6395 | symbol = XEXP (rtl, 0); | |
6396 | if (GET_CODE (symbol) != SYMBOL_REF) | |
6397 | return; | |
6398 | ||
6617cbc1 | 6399 | flags = SYMBOL_REF_FLAGS (symbol) & SYMBOL_FLAG_HAS_BLOCK_INFO; |
001be062 | 6400 | if (TREE_CODE (decl) == FUNCTION_DECL) |
6401 | flags |= SYMBOL_FLAG_FUNCTION; | |
883b2e73 | 6402 | if (targetm.binds_local_p (decl)) |
001be062 | 6403 | flags |= SYMBOL_FLAG_LOCAL; |
9dda1f80 | 6404 | if (targetm.have_tls && TREE_CODE (decl) == VAR_DECL |
6405 | && DECL_THREAD_LOCAL_P (decl)) | |
1b53eb20 | 6406 | flags |= DECL_TLS_MODEL (decl) << SYMBOL_FLAG_TLS_SHIFT; |
a368426e | 6407 | else if (targetm.in_small_data_p (decl)) |
6408 | flags |= SYMBOL_FLAG_SMALL; | |
4c2ba603 | 6409 | /* ??? Why is DECL_EXTERNAL ever set for non-PUBLIC names? Without |
6410 | being PUBLIC, the thing *must* be defined in this translation unit. | |
6411 | Prevent this buglet from being propagated into rtl code as well. */ | |
6412 | if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl)) | |
001be062 | 6413 | flags |= SYMBOL_FLAG_EXTERNAL; |
6414 | ||
6415 | SYMBOL_REF_FLAGS (symbol) = flags; | |
6416 | } | |
6417 | ||
7b4a38a6 | 6418 | /* By default, we do nothing for encode_section_info, so we need not |
6419 | do anything but discard the '*' marker. */ | |
6420 | ||
6421 | const char * | |
3180a54f | 6422 | default_strip_name_encoding (const char *str) |
7b4a38a6 | 6423 | { |
6424 | return str + (*str == '*'); | |
6425 | } | |
33459320 | 6426 | |
f2d0e9f1 | 6427 | #ifdef ASM_OUTPUT_DEF |
6428 | /* The default implementation of TARGET_ASM_OUTPUT_ANCHOR. Define the | |
6429 | anchor relative to ".", the current section position. */ | |
6430 | ||
6431 | void | |
6432 | default_asm_output_anchor (rtx symbol) | |
6433 | { | |
6434 | char buffer[100]; | |
6435 | ||
e6d8e73f | 6436 | sprintf (buffer, "*. + " HOST_WIDE_INT_PRINT_DEC, |
f2d0e9f1 | 6437 | SYMBOL_REF_BLOCK_OFFSET (symbol)); |
6438 | ASM_OUTPUT_DEF (asm_out_file, XSTR (symbol, 0), buffer); | |
6439 | } | |
6440 | #endif | |
6441 | ||
6442 | /* The default implementation of TARGET_USE_ANCHORS_FOR_SYMBOL_P. */ | |
6443 | ||
6444 | bool | |
a9f1838b | 6445 | default_use_anchors_for_symbol_p (const_rtx symbol) |
f2d0e9f1 | 6446 | { |
6447 | section *sect; | |
6448 | tree decl; | |
6449 | ||
6450 | /* Don't use anchors for mergeable sections. The linker might move | |
6451 | the objects around. */ | |
6452 | sect = SYMBOL_REF_BLOCK (symbol)->sect; | |
6453 | if (sect->common.flags & SECTION_MERGE) | |
6454 | return false; | |
6455 | ||
6456 | /* Don't use anchors for small data sections. The small data register | |
6457 | acts as an anchor for such sections. */ | |
6458 | if (sect->common.flags & SECTION_SMALL) | |
6459 | return false; | |
6460 | ||
6461 | decl = SYMBOL_REF_DECL (symbol); | |
6462 | if (decl && DECL_P (decl)) | |
6463 | { | |
6464 | /* Don't use section anchors for decls that might be defined by | |
6465 | other modules. */ | |
6466 | if (!targetm.binds_local_p (decl)) | |
6467 | return false; | |
6468 | ||
6469 | /* Don't use section anchors for decls that will be placed in a | |
6470 | small data section. */ | |
6471 | /* ??? Ideally, this check would be redundant with the SECTION_SMALL | |
6472 | one above. The problem is that we only use SECTION_SMALL for | |
6473 | sections that should be marked as small in the section directive. */ | |
6474 | if (targetm.in_small_data_p (decl)) | |
6475 | return false; | |
6476 | } | |
6477 | return true; | |
6478 | } | |
6479 | ||
33459320 | 6480 | /* Assume ELF-ish defaults, since that's pretty much the most liberal |
6481 | wrt cross-module name binding. */ | |
6482 | ||
6483 | bool | |
a9f1838b | 6484 | default_binds_local_p (const_tree exp) |
fb5a6c4c | 6485 | { |
c3ce66b0 | 6486 | return default_binds_local_p_1 (exp, flag_shlib); |
fb5a6c4c | 6487 | } |
6488 | ||
6489 | bool | |
a9f1838b | 6490 | default_binds_local_p_1 (const_tree exp, int shlib) |
33459320 | 6491 | { |
6492 | bool local_p; | |
6493 | ||
6494 | /* A non-decl is an entry in the constant pool. */ | |
6495 | if (!DECL_P (exp)) | |
6496 | local_p = true; | |
0a3ecdc1 | 6497 | /* Weakrefs may not bind locally, even though the weakref itself is |
6498 | always static and therefore local. */ | |
6499 | else if (lookup_attribute ("weakref", DECL_ATTRIBUTES (exp))) | |
6500 | local_p = false; | |
4d3af842 | 6501 | /* Static variables are always local. */ |
6502 | else if (! TREE_PUBLIC (exp)) | |
6503 | local_p = true; | |
0a3ecdc1 | 6504 | /* A variable is local if the user has said explicitly that it will |
6505 | be. */ | |
b215c058 | 6506 | else if (DECL_VISIBILITY_SPECIFIED (exp) |
0a3ecdc1 | 6507 | && DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT) |
33459320 | 6508 | local_p = true; |
0a3ecdc1 | 6509 | /* Variables defined outside this object might not be local. */ |
33459320 | 6510 | else if (DECL_EXTERNAL (exp)) |
6511 | local_p = false; | |
0a3ecdc1 | 6512 | /* If defined in this object and visibility is not default, must be |
6513 | local. */ | |
b212f378 | 6514 | else if (DECL_VISIBILITY (exp) != VISIBILITY_DEFAULT) |
6515 | local_p = true; | |
0a3ecdc1 | 6516 | /* Default visibility weak data can be overridden by a strong symbol |
6517 | in another module and so are not local. */ | |
6518 | else if (DECL_WEAK (exp)) | |
6519 | local_p = false; | |
33459320 | 6520 | /* If PIC, then assume that any global name can be overridden by |
0739a4b8 | 6521 | symbols resolved from other modules, unless we are compiling with |
6522 | -fwhole-program, which assumes that names are local. */ | |
fb5a6c4c | 6523 | else if (shlib) |
0739a4b8 | 6524 | local_p = flag_whole_program; |
33459320 | 6525 | /* Uninitialized COMMON variable may be unified with symbols |
6526 | resolved from other modules. */ | |
6527 | else if (DECL_COMMON (exp) | |
6528 | && (DECL_INITIAL (exp) == NULL | |
6529 | || DECL_INITIAL (exp) == error_mark_node)) | |
6530 | local_p = false; | |
6531 | /* Otherwise we're left with initialized (or non-common) global data | |
6532 | which is of necessity defined locally. */ | |
6533 | else | |
6534 | local_p = true; | |
6535 | ||
6536 | return local_p; | |
6537 | } | |
1f3233d1 | 6538 | |
805e22b2 | 6539 | /* Determine whether or not a pointer mode is valid. Assume defaults |
87fcb603 | 6540 | of ptr_mode or Pmode - can be overridden. */ |
805e22b2 | 6541 | bool |
3180a54f | 6542 | default_valid_pointer_mode (enum machine_mode mode) |
805e22b2 | 6543 | { |
6544 | return (mode == ptr_mode || mode == Pmode); | |
6545 | } | |
6546 | ||
67c1e638 | 6547 | /* Default function to output code that will globalize a label. A |
20833d12 | 6548 | target must define GLOBAL_ASM_OP or provide its own function to |
67c1e638 | 6549 | globalize a label. */ |
6550 | #ifdef GLOBAL_ASM_OP | |
6551 | void | |
3180a54f | 6552 | default_globalize_label (FILE * stream, const char *name) |
67c1e638 | 6553 | { |
6554 | fputs (GLOBAL_ASM_OP, stream); | |
6555 | assemble_name (stream, name); | |
6556 | putc ('\n', stream); | |
6557 | } | |
6558 | #endif /* GLOBAL_ASM_OP */ | |
3180a54f | 6559 | |
9afff52d | 6560 | /* Default function to output code that will globalize a declaration. */ |
6561 | void | |
6562 | default_globalize_decl_name (FILE * stream, tree decl) | |
6563 | { | |
6564 | const char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); | |
6565 | targetm.asm_out.globalize_label (stream, name); | |
6566 | } | |
6567 | ||
2f9fc8ef | 6568 | /* Default function to output a label for unwind information. The |
6569 | default is to do nothing. A target that needs nonlocal labels for | |
0bed3869 | 6570 | unwind information must provide its own function to do this. */ |
2f9fc8ef | 6571 | void |
6572 | default_emit_unwind_label (FILE * stream ATTRIBUTE_UNUSED, | |
6573 | tree decl ATTRIBUTE_UNUSED, | |
ef1074f7 | 6574 | int for_eh ATTRIBUTE_UNUSED, |
2f9fc8ef | 6575 | int empty ATTRIBUTE_UNUSED) |
b215c058 | 6576 | { |
6577 | } | |
6578 | ||
6579 | /* Default function to output a label to divide up the exception table. | |
6580 | The default is to do nothing. A target that needs/wants to divide | |
6581 | up the table must provide it's own function to do this. */ | |
6582 | void | |
6583 | default_emit_except_table_label (FILE * stream ATTRIBUTE_UNUSED) | |
6584 | { | |
2f9fc8ef | 6585 | } |
6586 | ||
805e22b2 | 6587 | /* This is how to output an internal numbered label where PREFIX is |
6588 | the class of label and LABELNO is the number within the class. */ | |
6589 | ||
6590 | void | |
3180a54f | 6591 | default_internal_label (FILE *stream, const char *prefix, |
6592 | unsigned long labelno) | |
805e22b2 | 6593 | { |
45ba1503 | 6594 | char *const buf = (char *) alloca (40 + strlen (prefix)); |
805e22b2 | 6595 | ASM_GENERATE_INTERNAL_LABEL (buf, prefix, labelno); |
48126f0c | 6596 | ASM_OUTPUT_INTERNAL_LABEL (stream, buf); |
805e22b2 | 6597 | } |
6598 | ||
92c473b8 | 6599 | /* This is the default behavior at the beginning of a file. It's |
6600 | controlled by two other target-hook toggles. */ | |
6601 | void | |
3180a54f | 6602 | default_file_start (void) |
92c473b8 | 6603 | { |
51653bc5 | 6604 | if (targetm.file_start_app_off |
6605 | && !(flag_verbose_asm || flag_debug_asm || flag_dump_rtl_in_asm)) | |
92c473b8 | 6606 | fputs (ASM_APP_OFF, asm_out_file); |
6607 | ||
6608 | if (targetm.file_start_file_directive) | |
6609 | output_file_directive (asm_out_file, main_input_filename); | |
6610 | } | |
6611 | ||
f6940372 | 6612 | /* This is a generic routine suitable for use as TARGET_ASM_FILE_END |
6613 | which emits a special section directive used to indicate whether or | |
6614 | not this object file needs an executable stack. This is primarily | |
6615 | a GNU extension to ELF but could be used on other targets. */ | |
4ee9c684 | 6616 | |
6617 | int trampolines_created; | |
6618 | ||
f6940372 | 6619 | void |
3180a54f | 6620 | file_end_indicate_exec_stack (void) |
f6940372 | 6621 | { |
6622 | unsigned int flags = SECTION_DEBUG; | |
6623 | if (trampolines_created) | |
6624 | flags |= SECTION_CODE; | |
6625 | ||
2f14b1f9 | 6626 | switch_to_section (get_section (".note.GNU-stack", flags, NULL)); |
6627 | } | |
6628 | ||
6629 | /* Output DIRECTIVE (a C string) followed by a newline. This is used as | |
6630 | a get_unnamed_section callback. */ | |
6631 | ||
6632 | void | |
6633 | output_section_asm_op (const void *directive) | |
6634 | { | |
6635 | fprintf (asm_out_file, "%s\n", (const char *) directive); | |
6636 | } | |
6637 | ||
6638 | /* Emit assembly code to switch to section NEW_SECTION. Do nothing if | |
6639 | the current section is NEW_SECTION. */ | |
6640 | ||
6641 | void | |
6642 | switch_to_section (section *new_section) | |
6643 | { | |
6644 | if (in_section == new_section) | |
6645 | return; | |
6646 | ||
6647 | if (new_section->common.flags & SECTION_FORGET) | |
6648 | in_section = NULL; | |
6649 | else | |
5fbee89d | 6650 | in_section = new_section; |
2f14b1f9 | 6651 | |
102e3995 | 6652 | switch (SECTION_STYLE (new_section)) |
2f14b1f9 | 6653 | { |
102e3995 | 6654 | case SECTION_NAMED: |
2f14b1f9 | 6655 | if (cfun |
abe32cce | 6656 | && !crtl->subsections.unlikely_text_section_name |
2f14b1f9 | 6657 | && strcmp (new_section->named.name, |
6658 | UNLIKELY_EXECUTED_TEXT_SECTION_NAME) == 0) | |
abe32cce | 6659 | crtl->subsections.unlikely_text_section_name = UNLIKELY_EXECUTED_TEXT_SECTION_NAME; |
2f14b1f9 | 6660 | |
6661 | targetm.asm_out.named_section (new_section->named.name, | |
6662 | new_section->named.common.flags, | |
6663 | new_section->named.decl); | |
102e3995 | 6664 | break; |
6665 | ||
6666 | case SECTION_UNNAMED: | |
6667 | new_section->unnamed.callback (new_section->unnamed.data); | |
6668 | break; | |
6669 | ||
6670 | case SECTION_NOSWITCH: | |
6671 | gcc_unreachable (); | |
6672 | break; | |
2f14b1f9 | 6673 | } |
2f14b1f9 | 6674 | |
6675 | new_section->common.flags |= SECTION_DECLARED; | |
f6940372 | 6676 | } |
6677 | ||
f2d0e9f1 | 6678 | /* If block symbol SYMBOL has not yet been assigned an offset, place |
6679 | it at the end of its block. */ | |
6680 | ||
6681 | void | |
6682 | place_block_symbol (rtx symbol) | |
6683 | { | |
6684 | unsigned HOST_WIDE_INT size, mask, offset; | |
6685 | struct constant_descriptor_rtx *desc; | |
6686 | unsigned int alignment; | |
6687 | struct object_block *block; | |
6688 | tree decl; | |
6689 | ||
102e3995 | 6690 | gcc_assert (SYMBOL_REF_BLOCK (symbol)); |
f2d0e9f1 | 6691 | if (SYMBOL_REF_BLOCK_OFFSET (symbol) >= 0) |
6692 | return; | |
6693 | ||
6694 | /* Work out the symbol's size and alignment. */ | |
6695 | if (CONSTANT_POOL_ADDRESS_P (symbol)) | |
6696 | { | |
6697 | desc = SYMBOL_REF_CONSTANT (symbol); | |
6698 | alignment = desc->align; | |
6699 | size = GET_MODE_SIZE (desc->mode); | |
6700 | } | |
6701 | else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol)) | |
6702 | { | |
6703 | decl = SYMBOL_REF_DECL (symbol); | |
6704 | alignment = get_constant_alignment (decl); | |
6705 | size = get_constant_size (decl); | |
6706 | } | |
6707 | else | |
6708 | { | |
6709 | decl = SYMBOL_REF_DECL (symbol); | |
6710 | alignment = DECL_ALIGN (decl); | |
6711 | size = tree_low_cst (DECL_SIZE_UNIT (decl), 1); | |
6712 | } | |
6713 | ||
6714 | /* Calculate the object's offset from the start of the block. */ | |
6715 | block = SYMBOL_REF_BLOCK (symbol); | |
6716 | mask = alignment / BITS_PER_UNIT - 1; | |
6717 | offset = (block->size + mask) & ~mask; | |
6718 | SYMBOL_REF_BLOCK_OFFSET (symbol) = offset; | |
6719 | ||
6720 | /* Record the block's new alignment and size. */ | |
6721 | block->alignment = MAX (block->alignment, alignment); | |
6722 | block->size = offset + size; | |
6723 | ||
6724 | VEC_safe_push (rtx, gc, block->objects, symbol); | |
6725 | } | |
6726 | ||
6727 | /* Return the anchor that should be used to address byte offset OFFSET | |
6728 | from the first object in BLOCK. MODEL is the TLS model used | |
6729 | to access it. */ | |
6730 | ||
6731 | rtx | |
6732 | get_section_anchor (struct object_block *block, HOST_WIDE_INT offset, | |
6733 | enum tls_model model) | |
6734 | { | |
6735 | char label[100]; | |
6736 | unsigned int begin, middle, end; | |
6737 | unsigned HOST_WIDE_INT min_offset, max_offset, range, bias, delta; | |
6738 | rtx anchor; | |
6739 | ||
6740 | /* Work out the anchor's offset. Use an offset of 0 for the first | |
6741 | anchor so that we don't pessimize the case where we take the address | |
6742 | of a variable at the beginning of the block. This is particularly | |
6743 | useful when a block has only one variable assigned to it. | |
6744 | ||
6745 | We try to place anchors RANGE bytes apart, so there can then be | |
6746 | anchors at +/-RANGE, +/-2 * RANGE, and so on, up to the limits of | |
6747 | a ptr_mode offset. With some target settings, the lowest such | |
6748 | anchor might be out of range for the lowest ptr_mode offset; | |
6749 | likewise the highest anchor for the highest offset. Use anchors | |
6750 | at the extreme ends of the ptr_mode range in such cases. | |
6751 | ||
6752 | All arithmetic uses unsigned integers in order to avoid | |
6753 | signed overflow. */ | |
6754 | max_offset = (unsigned HOST_WIDE_INT) targetm.max_anchor_offset; | |
6755 | min_offset = (unsigned HOST_WIDE_INT) targetm.min_anchor_offset; | |
6756 | range = max_offset - min_offset + 1; | |
6757 | if (range == 0) | |
6758 | offset = 0; | |
6759 | else | |
6760 | { | |
6761 | bias = 1 << (GET_MODE_BITSIZE (ptr_mode) - 1); | |
6762 | if (offset < 0) | |
6763 | { | |
6764 | delta = -(unsigned HOST_WIDE_INT) offset + max_offset; | |
6765 | delta -= delta % range; | |
6766 | if (delta > bias) | |
6767 | delta = bias; | |
6768 | offset = (HOST_WIDE_INT) (-delta); | |
6769 | } | |
6770 | else | |
6771 | { | |
6772 | delta = (unsigned HOST_WIDE_INT) offset - min_offset; | |
6773 | delta -= delta % range; | |
6774 | if (delta > bias - 1) | |
6775 | delta = bias - 1; | |
6776 | offset = (HOST_WIDE_INT) delta; | |
6777 | } | |
6778 | } | |
6779 | ||
6780 | /* Do a binary search to see if there's already an anchor we can use. | |
6781 | Set BEGIN to the new anchor's index if not. */ | |
6782 | begin = 0; | |
6783 | end = VEC_length (rtx, block->anchors); | |
6784 | while (begin != end) | |
6785 | { | |
6786 | middle = (end + begin) / 2; | |
6787 | anchor = VEC_index (rtx, block->anchors, middle); | |
6788 | if (SYMBOL_REF_BLOCK_OFFSET (anchor) > offset) | |
6789 | end = middle; | |
6790 | else if (SYMBOL_REF_BLOCK_OFFSET (anchor) < offset) | |
6791 | begin = middle + 1; | |
6792 | else if (SYMBOL_REF_TLS_MODEL (anchor) > model) | |
6793 | end = middle; | |
6794 | else if (SYMBOL_REF_TLS_MODEL (anchor) < model) | |
6795 | begin = middle + 1; | |
6796 | else | |
6797 | return anchor; | |
6798 | } | |
6799 | ||
6800 | /* Create a new anchor with a unique label. */ | |
6801 | ASM_GENERATE_INTERNAL_LABEL (label, "LANCHOR", anchor_labelno++); | |
6802 | anchor = create_block_symbol (ggc_strdup (label), block, offset); | |
6803 | SYMBOL_REF_FLAGS (anchor) |= SYMBOL_FLAG_LOCAL | SYMBOL_FLAG_ANCHOR; | |
6804 | SYMBOL_REF_FLAGS (anchor) |= model << SYMBOL_FLAG_TLS_SHIFT; | |
6805 | ||
6806 | /* Insert it at index BEGIN. */ | |
6807 | VEC_safe_insert (rtx, gc, block->anchors, begin, anchor); | |
6808 | return anchor; | |
6809 | } | |
6810 | ||
6811 | /* Output the objects in BLOCK. */ | |
6812 | ||
6813 | static void | |
6814 | output_object_block (struct object_block *block) | |
6815 | { | |
6816 | struct constant_descriptor_rtx *desc; | |
6817 | unsigned int i; | |
6818 | HOST_WIDE_INT offset; | |
6819 | tree decl; | |
6820 | rtx symbol; | |
6821 | ||
6822 | if (block->objects == NULL) | |
6823 | return; | |
6824 | ||
6825 | /* Switch to the section and make sure that the first byte is | |
6826 | suitably aligned. */ | |
6827 | switch_to_section (block->sect); | |
6828 | assemble_align (block->alignment); | |
6829 | ||
6830 | /* Define the values of all anchors relative to the current section | |
6831 | position. */ | |
6832 | for (i = 0; VEC_iterate (rtx, block->anchors, i, symbol); i++) | |
6833 | targetm.asm_out.output_anchor (symbol); | |
6834 | ||
6835 | /* Output the objects themselves. */ | |
6836 | offset = 0; | |
6837 | for (i = 0; VEC_iterate (rtx, block->objects, i, symbol); i++) | |
6838 | { | |
6839 | /* Move to the object's offset, padding with zeros if necessary. */ | |
6840 | assemble_zeros (SYMBOL_REF_BLOCK_OFFSET (symbol) - offset); | |
6841 | offset = SYMBOL_REF_BLOCK_OFFSET (symbol); | |
6842 | if (CONSTANT_POOL_ADDRESS_P (symbol)) | |
6843 | { | |
6844 | desc = SYMBOL_REF_CONSTANT (symbol); | |
6845 | output_constant_pool_1 (desc, 1); | |
6846 | offset += GET_MODE_SIZE (desc->mode); | |
6847 | } | |
6848 | else if (TREE_CONSTANT_POOL_ADDRESS_P (symbol)) | |
6849 | { | |
6850 | decl = SYMBOL_REF_DECL (symbol); | |
6851 | assemble_constant_contents (decl, XSTR (symbol, 0), | |
6852 | get_constant_alignment (decl)); | |
6853 | offset += get_constant_size (decl); | |
6854 | } | |
6855 | else | |
6856 | { | |
6857 | decl = SYMBOL_REF_DECL (symbol); | |
6858 | assemble_variable_contents (decl, XSTR (symbol, 0), false); | |
6859 | offset += tree_low_cst (DECL_SIZE_UNIT (decl), 1); | |
6860 | } | |
6861 | } | |
6862 | } | |
6863 | ||
6864 | /* A htab_traverse callback used to call output_object_block for | |
6865 | each member of object_block_htab. */ | |
6866 | ||
6867 | static int | |
6868 | output_object_block_htab (void **slot, void *data ATTRIBUTE_UNUSED) | |
6869 | { | |
6870 | output_object_block ((struct object_block *) (*slot)); | |
6871 | return 1; | |
6872 | } | |
6873 | ||
6874 | /* Output the definitions of all object_blocks. */ | |
6875 | ||
6876 | void | |
6877 | output_object_blocks (void) | |
6878 | { | |
6879 | htab_traverse (object_block_htab, output_object_block_htab, NULL); | |
6880 | } | |
6881 | ||
7c6733e8 | 6882 | /* This function provides a possible implementation of the |
6883 | TARGET_ASM_RECORD_GCC_SWITCHES target hook for ELF targets. When triggered | |
6884 | by -frecord-gcc-switches it creates a new mergeable, string section in the | |
6885 | assembler output file called TARGET_ASM_RECORD_GCC_SWITCHES_SECTION which | |
6886 | contains the switches in ASCII format. | |
6887 | ||
6888 | FIXME: This code does not correctly handle double quote characters | |
6889 | that appear inside strings, (it strips them rather than preserving them). | |
6890 | FIXME: ASM_OUTPUT_ASCII, as defined in config/elfos.h will not emit NUL | |
6891 | characters - instead it treats them as sub-string separators. Since | |
6892 | we want to emit NUL strings terminators into the object file we have to use | |
6893 | ASM_OUTPUT_SKIP. */ | |
6894 | ||
6895 | int | |
6896 | elf_record_gcc_switches (print_switch_type type, const char * name) | |
6897 | { | |
6898 | static char buffer[1024]; | |
6899 | ||
6900 | /* This variable is used as part of a simplistic heuristic to detect | |
6901 | command line switches which take an argument: | |
6902 | ||
6903 | "If a command line option does not start with a dash then | |
6904 | it is an argument for the previous command line option." | |
6905 | ||
6906 | This fails in the case of the command line option which is the name | |
6907 | of the file to compile, but otherwise it is pretty reasonable. */ | |
6908 | static bool previous_name_held_back = FALSE; | |
6909 | ||
6910 | switch (type) | |
6911 | { | |
6912 | case SWITCH_TYPE_PASSED: | |
6913 | if (* name != '-') | |
6914 | { | |
6915 | if (previous_name_held_back) | |
6916 | { | |
6917 | unsigned int len = strlen (buffer); | |
6918 | ||
6919 | snprintf (buffer + len, sizeof buffer - len, " %s", name); | |
6920 | ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer)); | |
ff831d3c | 6921 | ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1); |
7c6733e8 | 6922 | previous_name_held_back = FALSE; |
6923 | } | |
6924 | else | |
6925 | { | |
6926 | strncpy (buffer, name, sizeof buffer); | |
6927 | ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer)); | |
ff831d3c | 6928 | ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1); |
7c6733e8 | 6929 | } |
6930 | } | |
6931 | else | |
6932 | { | |
6933 | if (previous_name_held_back) | |
6934 | { | |
6935 | ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer)); | |
ff831d3c | 6936 | ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1); |
7c6733e8 | 6937 | } |
6938 | ||
6939 | strncpy (buffer, name, sizeof buffer); | |
6940 | previous_name_held_back = TRUE; | |
6941 | } | |
6942 | break; | |
6943 | ||
6944 | case SWITCH_TYPE_DESCRIPTIVE: | |
6945 | if (name == NULL) | |
6946 | { | |
6947 | /* Distinguish between invocations where name is NULL. */ | |
6948 | static bool started = false; | |
6949 | ||
6950 | if (started) | |
6951 | { | |
6952 | if (previous_name_held_back) | |
6953 | { | |
6954 | ASM_OUTPUT_ASCII (asm_out_file, buffer, strlen (buffer)); | |
ff831d3c | 6955 | ASM_OUTPUT_SKIP (asm_out_file, (unsigned HOST_WIDE_INT) 1); |
7c6733e8 | 6956 | } |
6957 | } | |
6958 | else | |
6959 | { | |
6960 | section * sec; | |
6961 | ||
6962 | sec = get_section (targetm.asm_out.record_gcc_switches_section, | |
6963 | SECTION_DEBUG | |
6964 | | SECTION_MERGE | |
6965 | | SECTION_STRINGS | |
6966 | | (SECTION_ENTSIZE & 1), | |
6967 | NULL); | |
6968 | switch_to_section (sec); | |
6969 | started = true; | |
6970 | } | |
6971 | } | |
6972 | ||
6973 | default: | |
6974 | break; | |
6975 | } | |
6976 | ||
6977 | /* The return value is currently ignored by the caller, but must be 0. | |
6978 | For -fverbose-asm the return value would be the number of characters | |
6979 | emitted into the assembler file. */ | |
6980 | return 0; | |
6981 | } | |
6982 | ||
44b23e05 | 6983 | /* Emit text to declare externally defined symbols. It is needed to |
6984 | properly support non-default visibility. */ | |
6985 | void | |
6986 | default_elf_asm_output_external (FILE *file ATTRIBUTE_UNUSED, | |
6987 | tree decl, | |
6988 | const char *name ATTRIBUTE_UNUSED) | |
6989 | { | |
6990 | /* We output the name if and only if TREE_SYMBOL_REFERENCED is | |
6991 | set in order to avoid putting out names that are never really | |
6992 | used. */ | |
6993 | if (TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)) | |
6994 | && targetm.binds_local_p (decl)) | |
6995 | maybe_assemble_visibility (decl); | |
6996 | } | |
6997 | ||
1f3233d1 | 6998 | #include "gt-varasm.h" |