111
|
1 /* LTO symbol table.
|
|
2 Copyright (C) 2009-2017 Free Software Foundation, Inc.
|
|
3 Contributed by CodeSourcery, Inc.
|
|
4
|
|
5 This file is part of GCC.
|
|
6
|
|
7 GCC is free software; you can redistribute it and/or modify it under
|
|
8 the terms of the GNU General Public License as published by the Free
|
|
9 Software Foundation; either version 3, or (at your option) any later
|
|
10 version.
|
|
11
|
|
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with GCC; see the file COPYING3. If not see
|
|
19 <http://www.gnu.org/licenses/>. */
|
|
20
|
|
21 #include "config.h"
|
|
22 #include "system.h"
|
|
23 #include "coretypes.h"
|
|
24 #include "target.h"
|
|
25 #include "function.h"
|
|
26 #include "basic-block.h"
|
|
27 #include "tree.h"
|
|
28 #include "gimple.h"
|
|
29 #include "cgraph.h"
|
|
30 #include "lto-streamer.h"
|
|
31 #include "ipa-utils.h"
|
|
32 #include "builtins.h"
|
|
33 #include "alias.h"
|
|
34 #include "lto-symtab.h"
|
|
35 #include "stringpool.h"
|
|
36 #include "attribs.h"
|
|
37
|
|
38 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
|
|
39 all edges and removing the old node. */
|
|
40
|
|
41 static void
|
|
42 lto_cgraph_replace_node (struct cgraph_node *node,
|
|
43 struct cgraph_node *prevailing_node)
|
|
44 {
|
|
45 struct cgraph_edge *e, *next;
|
|
46 bool compatible_p;
|
|
47
|
|
48 if (symtab->dump_file)
|
|
49 {
|
|
50 fprintf (symtab->dump_file, "Replacing cgraph node %s by %s"
|
|
51 " for symbol %s\n",
|
|
52 node->dump_name (),
|
|
53 prevailing_node->dump_name (),
|
|
54 IDENTIFIER_POINTER ((*targetm.asm_out.mangle_assembler_name)
|
|
55 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (node->decl)))));
|
|
56 }
|
|
57
|
|
58 /* Merge node flags. */
|
|
59 if (node->force_output)
|
|
60 prevailing_node->mark_force_output ();
|
|
61 if (node->forced_by_abi)
|
|
62 prevailing_node->forced_by_abi = true;
|
|
63 if (node->address_taken)
|
|
64 {
|
|
65 gcc_assert (!prevailing_node->global.inlined_to);
|
|
66 prevailing_node->mark_address_taken ();
|
|
67 }
|
|
68 if (node->definition && prevailing_node->definition
|
|
69 && DECL_COMDAT (node->decl) && DECL_COMDAT (prevailing_node->decl))
|
|
70 prevailing_node->merged_comdat = true;
|
|
71
|
|
72 /* Redirect all incoming edges. */
|
|
73 compatible_p
|
|
74 = types_compatible_p (TREE_TYPE (TREE_TYPE (prevailing_node->decl)),
|
|
75 TREE_TYPE (TREE_TYPE (node->decl)));
|
|
76 for (e = node->callers; e; e = next)
|
|
77 {
|
|
78 next = e->next_caller;
|
|
79 e->redirect_callee (prevailing_node);
|
|
80 /* If there is a mismatch between the supposed callee return type and
|
|
81 the real one do not attempt to inline this function.
|
|
82 ??? We really need a way to match function signatures for ABI
|
|
83 compatibility and perform related promotions at inlining time. */
|
|
84 if (!compatible_p)
|
|
85 {
|
|
86 e->inline_failed = CIF_LTO_MISMATCHED_DECLARATIONS;
|
|
87 e->call_stmt_cannot_inline_p = 1;
|
|
88 }
|
|
89 }
|
|
90 /* Redirect incomming references. */
|
|
91 prevailing_node->clone_referring (node);
|
|
92
|
|
93 /* Fix instrumentation references. */
|
|
94 if (node->instrumented_version)
|
|
95 {
|
|
96 gcc_assert (node->instrumentation_clone
|
|
97 == prevailing_node->instrumentation_clone);
|
|
98 node->instrumented_version->instrumented_version = prevailing_node;
|
|
99 if (!prevailing_node->instrumented_version)
|
|
100 prevailing_node->instrumented_version = node->instrumented_version;
|
|
101 /* Need to reset node->instrumented_version to NULL,
|
|
102 otherwise node removal code would reset
|
|
103 node->instrumented_version->instrumented_version. */
|
|
104 node->instrumented_version = NULL;
|
|
105 }
|
|
106
|
|
107 lto_free_function_in_decl_state_for_node (node);
|
|
108
|
|
109 if (node->decl != prevailing_node->decl)
|
|
110 node->release_body ();
|
|
111
|
|
112 /* Finally remove the replaced node. */
|
|
113 node->remove ();
|
|
114 }
|
|
115
|
|
116 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
|
|
117 all edges and removing the old node. */
|
|
118
|
|
119 static void
|
|
120 lto_varpool_replace_node (varpool_node *vnode,
|
|
121 varpool_node *prevailing_node)
|
|
122 {
|
|
123 gcc_assert (!vnode->definition || prevailing_node->definition);
|
|
124 gcc_assert (!vnode->analyzed || prevailing_node->analyzed);
|
|
125
|
|
126 prevailing_node->clone_referring (vnode);
|
|
127 if (vnode->force_output)
|
|
128 prevailing_node->force_output = true;
|
|
129 if (vnode->forced_by_abi)
|
|
130 prevailing_node->forced_by_abi = true;
|
|
131
|
|
132 /* Be sure we can garbage collect the initializer. */
|
|
133 if (DECL_INITIAL (vnode->decl)
|
|
134 && vnode->decl != prevailing_node->decl)
|
|
135 DECL_INITIAL (vnode->decl) = error_mark_node;
|
|
136
|
|
137 /* Check and report ODR violations on virtual tables. */
|
|
138 if (DECL_VIRTUAL_P (vnode->decl) || DECL_VIRTUAL_P (prevailing_node->decl))
|
|
139 compare_virtual_tables (prevailing_node, vnode);
|
|
140
|
|
141 if (vnode->tls_model != prevailing_node->tls_model)
|
|
142 {
|
|
143 bool error = false;
|
|
144
|
|
145 /* Non-TLS and TLS never mix together. Also emulated model is not
|
|
146 compatible with anything else. */
|
|
147 if (prevailing_node->tls_model == TLS_MODEL_NONE
|
|
148 || prevailing_node->tls_model == TLS_MODEL_EMULATED
|
|
149 || vnode->tls_model == TLS_MODEL_NONE
|
|
150 || vnode->tls_model == TLS_MODEL_EMULATED)
|
|
151 error = true;
|
|
152 /* Linked is silently supporting transitions
|
|
153 GD -> IE, GD -> LE, LD -> LE, IE -> LE, LD -> IE.
|
|
154 Do the same transitions and error out on others. */
|
|
155 else if ((prevailing_node->tls_model == TLS_MODEL_REAL
|
|
156 || prevailing_node->tls_model == TLS_MODEL_LOCAL_DYNAMIC)
|
|
157 && (vnode->tls_model == TLS_MODEL_INITIAL_EXEC
|
|
158 || vnode->tls_model == TLS_MODEL_LOCAL_EXEC))
|
|
159 prevailing_node->tls_model = vnode->tls_model;
|
|
160 else if ((vnode->tls_model == TLS_MODEL_REAL
|
|
161 || vnode->tls_model == TLS_MODEL_LOCAL_DYNAMIC)
|
|
162 && (prevailing_node->tls_model == TLS_MODEL_INITIAL_EXEC
|
|
163 || prevailing_node->tls_model == TLS_MODEL_LOCAL_EXEC))
|
|
164 ;
|
|
165 else if (prevailing_node->tls_model == TLS_MODEL_INITIAL_EXEC
|
|
166 && vnode->tls_model == TLS_MODEL_LOCAL_EXEC)
|
|
167 prevailing_node->tls_model = vnode->tls_model;
|
|
168 else if (vnode->tls_model == TLS_MODEL_INITIAL_EXEC
|
|
169 && prevailing_node->tls_model == TLS_MODEL_LOCAL_EXEC)
|
|
170 ;
|
|
171 else
|
|
172 error = true;
|
|
173 if (error)
|
|
174 {
|
|
175 error_at (DECL_SOURCE_LOCATION (vnode->decl),
|
|
176 "%qD is defined with tls model %s", vnode->decl, tls_model_names [vnode->tls_model]);
|
|
177 inform (DECL_SOURCE_LOCATION (prevailing_node->decl),
|
|
178 "previously defined here as %s",
|
|
179 tls_model_names [prevailing_node->tls_model]);
|
|
180 }
|
|
181 }
|
|
182 /* Finally remove the replaced node. */
|
|
183 vnode->remove ();
|
|
184 }
|
|
185
|
|
186 /* Return non-zero if we want to output waring about T1 and T2.
|
|
187 Return value is a bitmask of reasons of violation:
|
|
188 Bit 0 indicates that types are not compatible.
|
|
189 Bit 1 indicates that types are not compatible because of C++ ODR rule.
|
|
190 If COMMON_OR_EXTERN is true, do not warn on size mismatches of arrays.
|
|
191 Bit 2 indicates that types are not ODR compatible
|
|
192
|
|
193 The interoperability rules are language specific. At present we do only
|
|
194 full checking for C++ ODR rule and for other languages we do basic check
|
|
195 that data structures are of same size and TBAA compatible. Our TBAA
|
|
196 implementation should be coarse enough so all valid type transitions
|
|
197 across different languages are allowed.
|
|
198
|
|
199 In partiucular we thus allow almost arbitrary type changes with
|
|
200 -fno-strict-aliasing which may be tough of as a feature rather than bug
|
|
201 as it allows to implement dodgy tricks in the language runtimes.
|
|
202
|
|
203 Naturally this code can be strenghtened significantly if we could track
|
|
204 down the language of origin. */
|
|
205
|
|
206 static int
|
|
207 warn_type_compatibility_p (tree prevailing_type, tree type,
|
|
208 bool common_or_extern)
|
|
209 {
|
|
210 int lev = 0;
|
|
211 bool odr_p = odr_or_derived_type_p (prevailing_type)
|
|
212 && odr_or_derived_type_p (type);
|
|
213
|
|
214 if (prevailing_type == type)
|
|
215 return 0;
|
|
216
|
|
217 /* C++ provide a robust way to check for type compatibility via the ODR
|
|
218 rule. */
|
|
219 if (odr_p && !odr_types_equivalent_p (prevailing_type, type))
|
|
220 lev |= 2;
|
|
221
|
|
222 /* Function types needs special care, because types_compatible_p never
|
|
223 thinks prototype is compatible to non-prototype. */
|
|
224 if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE)
|
|
225 {
|
|
226 if (TREE_CODE (type) != TREE_CODE (prevailing_type))
|
|
227 lev |= 1;
|
|
228 lev |= warn_type_compatibility_p (TREE_TYPE (prevailing_type),
|
|
229 TREE_TYPE (type), false);
|
|
230 if (TREE_CODE (type) == METHOD_TYPE
|
|
231 && TREE_CODE (prevailing_type) == METHOD_TYPE)
|
|
232 lev |= warn_type_compatibility_p (TYPE_METHOD_BASETYPE (prevailing_type),
|
|
233 TYPE_METHOD_BASETYPE (type), false);
|
|
234 if (prototype_p (prevailing_type) && prototype_p (type)
|
|
235 && TYPE_ARG_TYPES (prevailing_type) != TYPE_ARG_TYPES (type))
|
|
236 {
|
|
237 tree parm1, parm2;
|
|
238 for (parm1 = TYPE_ARG_TYPES (prevailing_type),
|
|
239 parm2 = TYPE_ARG_TYPES (type);
|
|
240 parm1 && parm2;
|
|
241 parm1 = TREE_CHAIN (parm1),
|
|
242 parm2 = TREE_CHAIN (parm2))
|
|
243 lev |= warn_type_compatibility_p (TREE_VALUE (parm1),
|
|
244 TREE_VALUE (parm2), false);
|
|
245 if (parm1 || parm2)
|
|
246 lev |= odr_p ? 3 : 1;
|
|
247 }
|
|
248 if (comp_type_attributes (prevailing_type, type) == 0)
|
|
249 lev |= 1;
|
|
250 return lev;
|
|
251 }
|
|
252
|
|
253 /* Get complete type. */
|
|
254 prevailing_type = TYPE_MAIN_VARIANT (prevailing_type);
|
|
255 type = TYPE_MAIN_VARIANT (type);
|
|
256
|
|
257 /* We can not use types_compatible_p because we permit some changes
|
|
258 across types. For example unsigned size_t and "signed size_t" may be
|
|
259 compatible when merging C and Fortran types. */
|
|
260 if (COMPLETE_TYPE_P (prevailing_type)
|
|
261 && COMPLETE_TYPE_P (type)
|
|
262 /* While global declarations are never variadic, we can recurse here
|
|
263 for function parameter types. */
|
|
264 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST
|
|
265 && TREE_CODE (TYPE_SIZE (prevailing_type)) == INTEGER_CST
|
|
266 && !tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (prevailing_type)))
|
|
267 {
|
|
268 /* As a special case do not warn about merging
|
|
269 int a[];
|
|
270 and
|
|
271 int a[]={1,2,3};
|
|
272 here the first declaration is COMMON or EXTERN
|
|
273 and sizeof(a) == sizeof (int). */
|
|
274 if (!common_or_extern
|
|
275 || TREE_CODE (type) != ARRAY_TYPE
|
|
276 || TYPE_SIZE (type) != TYPE_SIZE (TREE_TYPE (type)))
|
|
277 lev |= 1;
|
|
278 }
|
|
279
|
|
280 /* Verify TBAA compatibility. Take care of alias set 0 and the fact that
|
|
281 we make ptr_type_node to TBAA compatible with every other type. */
|
|
282 if (type_with_alias_set_p (type) && type_with_alias_set_p (prevailing_type))
|
|
283 {
|
|
284 alias_set_type set1 = get_alias_set (type);
|
|
285 alias_set_type set2 = get_alias_set (prevailing_type);
|
|
286
|
|
287 if (set1 && set2 && set1 != set2
|
|
288 && (!POINTER_TYPE_P (type) || !POINTER_TYPE_P (prevailing_type)
|
|
289 || (set1 != TYPE_ALIAS_SET (ptr_type_node)
|
|
290 && set2 != TYPE_ALIAS_SET (ptr_type_node))))
|
|
291 lev |= 5;
|
|
292 }
|
|
293
|
|
294 return lev;
|
|
295 }
|
|
296
|
|
297 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
|
|
298 Return false if the symbols are not fully compatible and a diagnostic
|
|
299 should be emitted. */
|
|
300
|
|
301 static bool
|
|
302 lto_symtab_merge (symtab_node *prevailing, symtab_node *entry)
|
|
303 {
|
|
304 tree prevailing_decl = prevailing->decl;
|
|
305 tree decl = entry->decl;
|
|
306
|
|
307 if (prevailing_decl == decl)
|
|
308 return true;
|
|
309
|
|
310 if (TREE_CODE (decl) != TREE_CODE (prevailing_decl))
|
|
311 return false;
|
|
312
|
|
313 /* Merge decl state in both directions, we may still end up using
|
|
314 the new decl. */
|
|
315 TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
|
|
316 TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
|
|
317
|
|
318 /* The linker may ask us to combine two incompatible symbols.
|
|
319 Detect this case and notify the caller of required diagnostics. */
|
|
320
|
|
321 if (TREE_CODE (decl) == FUNCTION_DECL)
|
|
322 {
|
|
323 /* Merge decl state in both directions, we may still end up using
|
|
324 the new decl. */
|
|
325 DECL_POSSIBLY_INLINED (prevailing_decl) |= DECL_POSSIBLY_INLINED (decl);
|
|
326 DECL_POSSIBLY_INLINED (decl) |= DECL_POSSIBLY_INLINED (prevailing_decl);
|
|
327
|
|
328 if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl),
|
|
329 TREE_TYPE (decl),
|
|
330 DECL_COMMON (decl)
|
|
331 || DECL_EXTERNAL (decl)))
|
|
332 return false;
|
|
333
|
|
334 return true;
|
|
335 }
|
|
336
|
|
337 if (warn_type_compatibility_p (TREE_TYPE (prevailing_decl),
|
|
338 TREE_TYPE (decl),
|
|
339 DECL_COMMON (decl) || DECL_EXTERNAL (decl)))
|
|
340 return false;
|
|
341
|
|
342 /* There is no point in comparing too many details of the decls here.
|
|
343 The type compatibility checks or the completing of types has properly
|
|
344 dealt with most issues. */
|
|
345
|
|
346 /* The following should all not invoke fatal errors as in non-LTO
|
|
347 mode the linker wouldn't complain either. Just emit warnings. */
|
|
348
|
|
349 /* Report a warning if user-specified alignments do not match. */
|
|
350 if ((DECL_USER_ALIGN (prevailing_decl) && DECL_USER_ALIGN (decl))
|
|
351 && DECL_ALIGN (prevailing_decl) < DECL_ALIGN (decl))
|
|
352 return false;
|
|
353
|
|
354 if (DECL_SIZE (decl) && DECL_SIZE (prevailing_decl)
|
|
355 && !tree_int_cst_equal (DECL_SIZE (decl), DECL_SIZE (prevailing_decl))
|
|
356 /* As a special case do not warn about merging
|
|
357 int a[];
|
|
358 and
|
|
359 int a[]={1,2,3};
|
|
360 here the first declaration is COMMON
|
|
361 and sizeof(a) == sizeof (int). */
|
|
362 && ((!DECL_COMMON (decl) && !DECL_EXTERNAL (decl))
|
|
363 || TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
|
|
364 || TYPE_SIZE (TREE_TYPE (decl))
|
|
365 != TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl)))))
|
|
366 return false;
|
|
367
|
|
368 return true;
|
|
369 }
|
|
370
|
|
371 /* Return true if the symtab entry E can be replaced by another symtab
|
|
372 entry. */
|
|
373
|
|
374 static bool
|
|
375 lto_symtab_resolve_replaceable_p (symtab_node *e)
|
|
376 {
|
|
377 if (DECL_EXTERNAL (e->decl)
|
|
378 || DECL_COMDAT (e->decl)
|
|
379 || DECL_ONE_ONLY (e->decl)
|
|
380 || DECL_WEAK (e->decl))
|
|
381 return true;
|
|
382
|
|
383 if (TREE_CODE (e->decl) == VAR_DECL)
|
|
384 return (DECL_COMMON (e->decl)
|
|
385 || (!flag_no_common && !DECL_INITIAL (e->decl)));
|
|
386
|
|
387 return false;
|
|
388 }
|
|
389
|
|
390 /* Return true, if the symbol E should be resolved by lto-symtab.
|
|
391 Those are all external symbols and all real symbols that are not static (we
|
|
392 handle renaming of static later in partitioning). */
|
|
393
|
|
394 static bool
|
|
395 lto_symtab_symbol_p (symtab_node *e)
|
|
396 {
|
|
397 if (!TREE_PUBLIC (e->decl) && !DECL_EXTERNAL (e->decl))
|
|
398 return false;
|
|
399 return e->real_symbol_p ();
|
|
400 }
|
|
401
|
|
402 /* Return true if the symtab entry E can be the prevailing one. */
|
|
403
|
|
404 static bool
|
|
405 lto_symtab_resolve_can_prevail_p (symtab_node *e)
|
|
406 {
|
|
407 if (!lto_symtab_symbol_p (e))
|
|
408 return false;
|
|
409
|
|
410 /* The C++ frontend ends up neither setting TREE_STATIC nor
|
|
411 DECL_EXTERNAL on virtual methods but only TREE_PUBLIC.
|
|
412 So do not reject !TREE_STATIC here but only DECL_EXTERNAL. */
|
|
413 if (DECL_EXTERNAL (e->decl))
|
|
414 return false;
|
|
415
|
|
416 return e->definition;
|
|
417 }
|
|
418
|
|
419 /* Resolve the symbol with the candidates in the chain *SLOT and store
|
|
420 their resolutions. */
|
|
421
|
|
422 static symtab_node *
|
|
423 lto_symtab_resolve_symbols (symtab_node *first)
|
|
424 {
|
|
425 symtab_node *e;
|
|
426 symtab_node *prevailing = NULL;
|
|
427
|
|
428 /* Always set e->node so that edges are updated to reflect decl merging. */
|
|
429 for (e = first; e; e = e->next_sharing_asm_name)
|
|
430 if (lto_symtab_symbol_p (e)
|
|
431 && (e->resolution == LDPR_PREVAILING_DEF_IRONLY
|
|
432 || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
|
|
433 || e->resolution == LDPR_PREVAILING_DEF))
|
|
434 {
|
|
435 prevailing = e;
|
|
436 break;
|
|
437 }
|
|
438
|
|
439 /* If the chain is already resolved there is nothing else to do. */
|
|
440 if (prevailing)
|
|
441 {
|
|
442 /* Assert it's the only one. */
|
|
443 for (e = prevailing->next_sharing_asm_name; e; e = e->next_sharing_asm_name)
|
|
444 if (lto_symtab_symbol_p (e)
|
|
445 && (e->resolution == LDPR_PREVAILING_DEF_IRONLY
|
|
446 || e->resolution == LDPR_PREVAILING_DEF_IRONLY_EXP
|
|
447 || e->resolution == LDPR_PREVAILING_DEF))
|
|
448 fatal_error (input_location, "multiple prevailing defs for %qE",
|
|
449 DECL_NAME (prevailing->decl));
|
|
450 return prevailing;
|
|
451 }
|
|
452
|
|
453 /* Find the single non-replaceable prevailing symbol and
|
|
454 diagnose ODR violations. */
|
|
455 for (e = first; e; e = e->next_sharing_asm_name)
|
|
456 {
|
|
457 if (!lto_symtab_resolve_can_prevail_p (e))
|
|
458 continue;
|
|
459
|
|
460 /* If we have a non-replaceable definition it prevails. */
|
|
461 if (!lto_symtab_resolve_replaceable_p (e))
|
|
462 {
|
|
463 if (prevailing)
|
|
464 {
|
|
465 error_at (DECL_SOURCE_LOCATION (e->decl),
|
|
466 "%qD has already been defined", e->decl);
|
|
467 inform (DECL_SOURCE_LOCATION (prevailing->decl),
|
|
468 "previously defined here");
|
|
469 }
|
|
470 prevailing = e;
|
|
471 }
|
|
472 }
|
|
473 if (prevailing)
|
|
474 return prevailing;
|
|
475
|
|
476 /* Do a second round choosing one from the replaceable prevailing decls. */
|
|
477 for (e = first; e; e = e->next_sharing_asm_name)
|
|
478 {
|
|
479 if (!lto_symtab_resolve_can_prevail_p (e))
|
|
480 continue;
|
|
481
|
|
482 /* Choose the first function that can prevail as prevailing. */
|
|
483 if (TREE_CODE (e->decl) == FUNCTION_DECL)
|
|
484 {
|
|
485 prevailing = e;
|
|
486 break;
|
|
487 }
|
|
488
|
|
489 /* From variables that can prevail choose the largest one. */
|
|
490 if (!prevailing
|
|
491 || tree_int_cst_lt (DECL_SIZE (prevailing->decl),
|
|
492 DECL_SIZE (e->decl))
|
|
493 /* When variables are equivalent try to chose one that has useful
|
|
494 DECL_INITIAL. This makes sense for keyed vtables that are
|
|
495 DECL_EXTERNAL but initialized. In units that do not need them
|
|
496 we replace the initializer by error_mark_node to conserve
|
|
497 memory.
|
|
498
|
|
499 We know that the vtable is keyed outside the LTO unit - otherwise
|
|
500 the keyed instance would prevail. We still can preserve useful
|
|
501 info in the initializer. */
|
|
502 || (DECL_SIZE (prevailing->decl) == DECL_SIZE (e->decl)
|
|
503 && (DECL_INITIAL (e->decl)
|
|
504 && DECL_INITIAL (e->decl) != error_mark_node)
|
|
505 && (!DECL_INITIAL (prevailing->decl)
|
|
506 || DECL_INITIAL (prevailing->decl) == error_mark_node)))
|
|
507 prevailing = e;
|
|
508 }
|
|
509
|
|
510 return prevailing;
|
|
511 }
|
|
512
|
|
513 /* Decide if it is OK to merge DECL into PREVAILING.
|
|
514 Because we wrap most of uses of declarations in MEM_REF, we can tolerate
|
|
515 some differences but other code may inspect directly the DECL. */
|
|
516
|
|
517 static bool
|
|
518 lto_symtab_merge_p (tree prevailing, tree decl)
|
|
519 {
|
|
520 if (TREE_CODE (prevailing) != TREE_CODE (decl))
|
|
521 {
|
|
522 if (symtab->dump_file)
|
|
523 fprintf (symtab->dump_file, "Not merging decls; "
|
|
524 "TREE_CODE mismatch\n");
|
|
525 return false;
|
|
526 }
|
|
527 gcc_checking_assert (TREE_CHAIN (prevailing) == TREE_CHAIN (decl));
|
|
528
|
|
529 if (TREE_CODE (prevailing) == FUNCTION_DECL)
|
|
530 {
|
|
531 if (DECL_BUILT_IN (prevailing) != DECL_BUILT_IN (decl))
|
|
532 {
|
|
533 if (symtab->dump_file)
|
|
534 fprintf (symtab->dump_file, "Not merging decls; "
|
|
535 "DECL_BUILT_IN mismatch\n");
|
|
536 return false;
|
|
537 }
|
|
538 if (DECL_BUILT_IN (prevailing)
|
|
539 && (DECL_BUILT_IN_CLASS (prevailing) != DECL_BUILT_IN_CLASS (decl)
|
|
540 || DECL_FUNCTION_CODE (prevailing) != DECL_FUNCTION_CODE (decl)))
|
|
541 {
|
|
542 if (symtab->dump_file)
|
|
543 fprintf (symtab->dump_file, "Not merging decls; "
|
|
544 "DECL_BUILT_IN_CLASS or CODE mismatch\n");
|
|
545 return false;
|
|
546 }
|
|
547 }
|
|
548 if (DECL_ATTRIBUTES (prevailing) != DECL_ATTRIBUTES (decl))
|
|
549 {
|
|
550 tree prev_attr = lookup_attribute ("error", DECL_ATTRIBUTES (prevailing));
|
|
551 tree attr = lookup_attribute ("error", DECL_ATTRIBUTES (decl));
|
|
552 if ((prev_attr == NULL) != (attr == NULL)
|
|
553 || (prev_attr
|
|
554 && TREE_VALUE (TREE_VALUE (prev_attr))
|
|
555 != TREE_VALUE (TREE_VALUE (attr))))
|
|
556 {
|
|
557 if (symtab->dump_file)
|
|
558 fprintf (symtab->dump_file, "Not merging decls; "
|
|
559 "error attribute mismatch\n");
|
|
560 return false;
|
|
561 }
|
|
562
|
|
563 prev_attr = lookup_attribute ("warning", DECL_ATTRIBUTES (prevailing));
|
|
564 attr = lookup_attribute ("warning", DECL_ATTRIBUTES (decl));
|
|
565 if ((prev_attr == NULL) != (attr == NULL)
|
|
566 || (prev_attr
|
|
567 && TREE_VALUE (TREE_VALUE (prev_attr))
|
|
568 != TREE_VALUE (TREE_VALUE (attr))))
|
|
569 {
|
|
570 if (symtab->dump_file)
|
|
571 fprintf (symtab->dump_file, "Not merging decls; "
|
|
572 "warning attribute mismatch\n");
|
|
573 return false;
|
|
574 }
|
|
575 }
|
|
576 return true;
|
|
577 }
|
|
578
|
|
579 /* Merge all decls in the symbol table chain to the prevailing decl and
|
|
580 issue diagnostics about type mismatches. If DIAGNOSED_P is true
|
|
581 do not issue further diagnostics.*/
|
|
582
|
|
583 static void
|
|
584 lto_symtab_merge_decls_2 (symtab_node *first, bool diagnosed_p)
|
|
585 {
|
|
586 symtab_node *prevailing;
|
|
587 symtab_node *e;
|
|
588 vec<tree> mismatches = vNULL;
|
|
589 unsigned i;
|
|
590 tree decl;
|
|
591 bool tbaa_p = false;
|
|
592
|
|
593 /* Nothing to do for a single entry. */
|
|
594 prevailing = first;
|
|
595 if (!prevailing->next_sharing_asm_name)
|
|
596 return;
|
|
597
|
|
598 /* Try to merge each entry with the prevailing one. */
|
|
599 symtab_node *last_prevailing = prevailing, *next;
|
|
600 for (e = prevailing->next_sharing_asm_name; e; e = next)
|
|
601 {
|
|
602 next = e->next_sharing_asm_name;
|
|
603
|
|
604 /* Skip non-LTO symbols and symbols whose declaration we already
|
|
605 visited. */
|
|
606 if (lto_symtab_prevailing_decl (e->decl) != e->decl
|
|
607 || !lto_symtab_symbol_p (e)
|
|
608 || e->decl == prevailing->decl)
|
|
609 continue;
|
|
610
|
|
611 if (!lto_symtab_merge (prevailing, e)
|
|
612 && !diagnosed_p
|
|
613 && !DECL_ARTIFICIAL (e->decl))
|
|
614 mismatches.safe_push (e->decl);
|
|
615
|
|
616 symtab_node *this_prevailing;
|
|
617 for (this_prevailing = prevailing; ;
|
|
618 this_prevailing = this_prevailing->next_sharing_asm_name)
|
|
619 {
|
|
620 if (this_prevailing->decl != e->decl
|
|
621 && lto_symtab_merge_p (this_prevailing->decl, e->decl))
|
|
622 break;
|
|
623 if (this_prevailing == last_prevailing)
|
|
624 {
|
|
625 this_prevailing = NULL;
|
|
626 break;
|
|
627 }
|
|
628 }
|
|
629
|
|
630 if (this_prevailing)
|
|
631 lto_symtab_prevail_decl (this_prevailing->decl, e->decl);
|
|
632 /* Maintain LRU list: relink the new prevaililng symbol
|
|
633 just after previaling node in the chain and update last_prevailing.
|
|
634 Since the number of possible declarations of a given symbol is
|
|
635 small, this should be faster than building a hash. */
|
|
636 else if (e == prevailing->next_sharing_asm_name)
|
|
637 last_prevailing = e;
|
|
638 else
|
|
639 {
|
|
640 if (e->next_sharing_asm_name)
|
|
641 e->next_sharing_asm_name->previous_sharing_asm_name
|
|
642 = e->previous_sharing_asm_name;
|
|
643 e->previous_sharing_asm_name->next_sharing_asm_name
|
|
644 = e->next_sharing_asm_name;
|
|
645 e->previous_sharing_asm_name = prevailing;
|
|
646 e->next_sharing_asm_name = prevailing->next_sharing_asm_name;
|
|
647 prevailing->next_sharing_asm_name->previous_sharing_asm_name = e;
|
|
648 prevailing->next_sharing_asm_name = e;
|
|
649 if (last_prevailing == prevailing)
|
|
650 last_prevailing = e;
|
|
651 }
|
|
652 }
|
|
653 if (mismatches.is_empty ())
|
|
654 return;
|
|
655
|
|
656 /* Diagnose all mismatched re-declarations. */
|
|
657 FOR_EACH_VEC_ELT (mismatches, i, decl)
|
|
658 {
|
|
659 /* Do not diagnose two built-in declarations, there is no useful
|
|
660 location in that case. It also happens for AVR if two built-ins
|
|
661 use the same asm name because their libgcc assembler code is the
|
|
662 same, see PR78562. */
|
|
663 if (DECL_IS_BUILTIN (prevailing->decl)
|
|
664 && DECL_IS_BUILTIN (decl))
|
|
665 continue;
|
|
666
|
|
667 int level = warn_type_compatibility_p (TREE_TYPE (prevailing->decl),
|
|
668 TREE_TYPE (decl),
|
|
669 DECL_COMDAT (decl));
|
|
670 if (level)
|
|
671 {
|
|
672 bool diag = false;
|
|
673 if (level & 2)
|
|
674 diag = warning_at (DECL_SOURCE_LOCATION (decl),
|
|
675 OPT_Wodr,
|
|
676 "%qD violates the C++ One Definition Rule ",
|
|
677 decl);
|
|
678 if (!diag && (level & 1))
|
|
679 diag = warning_at (DECL_SOURCE_LOCATION (decl),
|
|
680 OPT_Wlto_type_mismatch,
|
|
681 "type of %qD does not match original "
|
|
682 "declaration", decl);
|
|
683 if (diag)
|
|
684 {
|
|
685 warn_types_mismatch (TREE_TYPE (prevailing->decl),
|
|
686 TREE_TYPE (decl),
|
|
687 DECL_SOURCE_LOCATION (prevailing->decl),
|
|
688 DECL_SOURCE_LOCATION (decl));
|
|
689 if ((level & 4)
|
|
690 && !TREE_READONLY (prevailing->decl))
|
|
691 tbaa_p = true;
|
|
692 }
|
|
693 diagnosed_p |= diag;
|
|
694 }
|
|
695 else if ((DECL_USER_ALIGN (prevailing->decl)
|
|
696 && DECL_USER_ALIGN (decl))
|
|
697 && DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
|
|
698 {
|
|
699 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl),
|
|
700 OPT_Wlto_type_mismatch,
|
|
701 "alignment of %qD is bigger than "
|
|
702 "original declaration", decl);
|
|
703 }
|
|
704 else
|
|
705 diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl),
|
|
706 OPT_Wlto_type_mismatch,
|
|
707 "size of %qD differ from the size of "
|
|
708 "original declaration", decl);
|
|
709 }
|
|
710 if (diagnosed_p)
|
|
711 inform (DECL_SOURCE_LOCATION (prevailing->decl),
|
|
712 "%qD was previously declared here", prevailing->decl);
|
|
713 if (tbaa_p)
|
|
714 inform (DECL_SOURCE_LOCATION (prevailing->decl),
|
|
715 "code may be misoptimized unless "
|
|
716 "-fno-strict-aliasing is used");
|
|
717
|
|
718 mismatches.release ();
|
|
719 }
|
|
720
|
|
721 /* Helper to process the decl chain for the symbol table entry *SLOT. */
|
|
722
|
|
723 static void
|
|
724 lto_symtab_merge_decls_1 (symtab_node *first)
|
|
725 {
|
|
726 symtab_node *e;
|
|
727 symtab_node *prevailing;
|
|
728 bool diagnosed_p = false;
|
|
729
|
|
730 if (symtab->dump_file)
|
|
731 {
|
|
732 fprintf (symtab->dump_file, "Merging nodes for %s. Candidates:\n",
|
|
733 first->asm_name ());
|
|
734 for (e = first; e; e = e->next_sharing_asm_name)
|
|
735 if (TREE_PUBLIC (e->decl))
|
|
736 e->dump (symtab->dump_file);
|
|
737 }
|
|
738
|
|
739 /* Compute the symbol resolutions. This is a no-op when using the
|
|
740 linker plugin and resolution was decided by the linker. */
|
|
741 prevailing = lto_symtab_resolve_symbols (first);
|
|
742
|
|
743 /* If there's not a prevailing symbol yet it's an external reference.
|
|
744 Happens a lot during ltrans. Choose the first symbol with a
|
|
745 cgraph or a varpool node. */
|
|
746 if (!prevailing)
|
|
747 {
|
|
748 for (prevailing = first;
|
|
749 prevailing; prevailing = prevailing->next_sharing_asm_name)
|
|
750 if (lto_symtab_symbol_p (prevailing))
|
|
751 break;
|
|
752 if (!prevailing)
|
|
753 return;
|
|
754 /* For variables chose with a priority variant with vnode
|
|
755 attached (i.e. from unit where external declaration of
|
|
756 variable is actually used).
|
|
757 When there are multiple variants, chose one with size.
|
|
758 This is needed for C++ typeinfos, for example in
|
|
759 lto/20081204-1 there are typeifos in both units, just
|
|
760 one of them do have size. */
|
|
761 if (TREE_CODE (prevailing->decl) == VAR_DECL)
|
|
762 {
|
|
763 for (e = prevailing->next_sharing_asm_name;
|
|
764 e; e = e->next_sharing_asm_name)
|
|
765 if (!COMPLETE_TYPE_P (TREE_TYPE (prevailing->decl))
|
|
766 && COMPLETE_TYPE_P (TREE_TYPE (e->decl))
|
|
767 && lto_symtab_symbol_p (e))
|
|
768 prevailing = e;
|
|
769 }
|
|
770 /* For functions prefer the non-builtin if one is available. */
|
|
771 else if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
|
|
772 {
|
|
773 for (e = first; e; e = e->next_sharing_asm_name)
|
|
774 if (TREE_CODE (e->decl) == FUNCTION_DECL
|
|
775 && !DECL_BUILT_IN (e->decl)
|
|
776 && lto_symtab_symbol_p (e))
|
|
777 {
|
|
778 prevailing = e;
|
|
779 break;
|
|
780 }
|
|
781 }
|
|
782 }
|
|
783
|
|
784 symtab->symtab_prevail_in_asm_name_hash (prevailing);
|
|
785
|
|
786 /* Diagnose mismatched objects. */
|
|
787 for (e = prevailing->next_sharing_asm_name;
|
|
788 e; e = e->next_sharing_asm_name)
|
|
789 {
|
|
790 if (TREE_CODE (prevailing->decl)
|
|
791 == TREE_CODE (e->decl))
|
|
792 continue;
|
|
793 if (!lto_symtab_symbol_p (e))
|
|
794 continue;
|
|
795
|
|
796 switch (TREE_CODE (prevailing->decl))
|
|
797 {
|
|
798 case VAR_DECL:
|
|
799 gcc_assert (TREE_CODE (e->decl) == FUNCTION_DECL);
|
|
800 error_at (DECL_SOURCE_LOCATION (e->decl),
|
|
801 "variable %qD redeclared as function",
|
|
802 prevailing->decl);
|
|
803 break;
|
|
804
|
|
805 case FUNCTION_DECL:
|
|
806 gcc_assert (TREE_CODE (e->decl) == VAR_DECL);
|
|
807 error_at (DECL_SOURCE_LOCATION (e->decl),
|
|
808 "function %qD redeclared as variable",
|
|
809 prevailing->decl);
|
|
810 break;
|
|
811
|
|
812 default:
|
|
813 gcc_unreachable ();
|
|
814 }
|
|
815
|
|
816 diagnosed_p = true;
|
|
817 }
|
|
818 if (diagnosed_p)
|
|
819 inform (DECL_SOURCE_LOCATION (prevailing->decl),
|
|
820 "previously declared here");
|
|
821
|
|
822 /* Merge the chain to the single prevailing decl and diagnose
|
|
823 mismatches. */
|
|
824 lto_symtab_merge_decls_2 (prevailing, diagnosed_p);
|
|
825
|
|
826 if (symtab->dump_file)
|
|
827 {
|
|
828 fprintf (symtab->dump_file, "After resolution:\n");
|
|
829 for (e = prevailing; e; e = e->next_sharing_asm_name)
|
|
830 e->dump (symtab->dump_file);
|
|
831 }
|
|
832 }
|
|
833
|
|
834 /* Resolve and merge all symbol table chains to a prevailing decl. */
|
|
835
|
|
836 void
|
|
837 lto_symtab_merge_decls (void)
|
|
838 {
|
|
839 symtab_node *node;
|
|
840
|
|
841 /* Populate assembler name hash. */
|
|
842 symtab->symtab_initialize_asm_name_hash ();
|
|
843
|
|
844 FOR_EACH_SYMBOL (node)
|
|
845 if (!node->previous_sharing_asm_name
|
|
846 && node->next_sharing_asm_name)
|
|
847 lto_symtab_merge_decls_1 (node);
|
|
848 }
|
|
849
|
|
850 /* Helper to process the decl chain for the symbol table entry *SLOT. */
|
|
851
|
|
852 static void
|
|
853 lto_symtab_merge_symbols_1 (symtab_node *prevailing)
|
|
854 {
|
|
855 symtab_node *e;
|
|
856 symtab_node *next;
|
|
857
|
|
858 prevailing->decl->decl_with_vis.symtab_node = prevailing;
|
|
859
|
|
860 /* Replace the cgraph node of each entry with the prevailing one. */
|
|
861 for (e = prevailing->next_sharing_asm_name; e;
|
|
862 e = next)
|
|
863 {
|
|
864 next = e->next_sharing_asm_name;
|
|
865
|
|
866 if (!lto_symtab_symbol_p (e))
|
|
867 continue;
|
|
868 cgraph_node *ce = dyn_cast <cgraph_node *> (e);
|
|
869 symtab_node *to = symtab_node::get (lto_symtab_prevailing_decl (e->decl));
|
|
870
|
|
871 /* No matter how we are going to deal with resolution, we will ultimately
|
|
872 use prevailing definition. */
|
|
873 if (ce)
|
|
874 ipa_merge_profiles (dyn_cast<cgraph_node *> (prevailing),
|
|
875 dyn_cast<cgraph_node *> (e));
|
|
876
|
|
877 /* If we decided to replace the node by TO, do it. */
|
|
878 if (e != to)
|
|
879 {
|
|
880 if (ce)
|
|
881 lto_cgraph_replace_node (ce, dyn_cast<cgraph_node *> (to));
|
|
882 else if (varpool_node *ve = dyn_cast <varpool_node *> (e))
|
|
883 lto_varpool_replace_node (ve, dyn_cast<varpool_node *> (to));
|
|
884 }
|
|
885 /* Watch out for duplicated symbols for a given declaration. */
|
|
886 else if (!e->transparent_alias
|
|
887 || !e->definition || e->get_alias_target () != to)
|
|
888 {
|
|
889 /* We got a new declaration we do not want to merge. In this case
|
|
890 get rid of the existing definition and create a transparent
|
|
891 alias. */
|
|
892 if (ce)
|
|
893 {
|
|
894 lto_free_function_in_decl_state_for_node (ce);
|
|
895 if (!ce->weakref)
|
|
896 ce->release_body ();
|
|
897 ce->reset ();
|
|
898 symtab->call_cgraph_removal_hooks (ce);
|
|
899 }
|
|
900 else
|
|
901 {
|
|
902 DECL_INITIAL (e->decl) = error_mark_node;
|
|
903 if (e->lto_file_data)
|
|
904 {
|
|
905 lto_free_function_in_decl_state_for_node (e);
|
|
906 e->lto_file_data = NULL;
|
|
907 }
|
|
908 symtab->call_varpool_removal_hooks (dyn_cast<varpool_node *> (e));
|
|
909 }
|
|
910 e->remove_all_references ();
|
|
911 e->analyzed = e->body_removed = false;
|
|
912 e->resolve_alias (prevailing, true);
|
|
913 gcc_assert (e != prevailing);
|
|
914 }
|
|
915 }
|
|
916
|
|
917 return;
|
|
918 }
|
|
919
|
|
920 /* Merge cgraph nodes according to the symbol merging done by
|
|
921 lto_symtab_merge_decls. */
|
|
922
|
|
923 void
|
|
924 lto_symtab_merge_symbols (void)
|
|
925 {
|
|
926 symtab_node *node;
|
|
927
|
|
928 if (!flag_ltrans)
|
|
929 {
|
|
930 symtab->symtab_initialize_asm_name_hash ();
|
|
931
|
|
932 /* Do the actual merging.
|
|
933 At this point we invalidate hash translating decls into symtab nodes
|
|
934 because after removing one of duplicate decls the hash is not correcly
|
|
935 updated to the ohter dupliate. */
|
|
936 FOR_EACH_SYMBOL (node)
|
|
937 if (lto_symtab_symbol_p (node)
|
|
938 && node->next_sharing_asm_name
|
|
939 && !node->previous_sharing_asm_name)
|
|
940 lto_symtab_merge_symbols_1 (node);
|
|
941
|
|
942 /* Resolve weakref aliases whose target are now in the compilation unit.
|
|
943 also re-populate the hash translating decls into symtab nodes*/
|
|
944 FOR_EACH_SYMBOL (node)
|
|
945 {
|
|
946 cgraph_node *cnode, *cnode2;
|
|
947 varpool_node *vnode;
|
|
948 symtab_node *node2;
|
|
949
|
|
950 if (!node->analyzed && node->alias_target)
|
|
951 {
|
|
952 symtab_node *tgt = symtab_node::get_for_asmname (node->alias_target);
|
|
953 gcc_assert (node->weakref);
|
|
954 if (tgt)
|
|
955 node->resolve_alias (tgt, true);
|
|
956 }
|
|
957 /* If the symbol was preempted outside IR, see if we want to get rid
|
|
958 of the definition. */
|
|
959 if (node->analyzed
|
|
960 && !DECL_EXTERNAL (node->decl)
|
|
961 && (node->resolution == LDPR_PREEMPTED_REG
|
|
962 || node->resolution == LDPR_RESOLVED_IR
|
|
963 || node->resolution == LDPR_RESOLVED_EXEC
|
|
964 || node->resolution == LDPR_RESOLVED_DYN))
|
|
965 {
|
|
966 DECL_EXTERNAL (node->decl) = 1;
|
|
967 /* If alias to local symbol was preempted by external definition,
|
|
968 we know it is not pointing to the local symbol. Remove it. */
|
|
969 if (node->alias
|
|
970 && !node->weakref
|
|
971 && !node->transparent_alias
|
|
972 && node->get_alias_target ()->binds_to_current_def_p ())
|
|
973 {
|
|
974 node->alias = false;
|
|
975 node->remove_all_references ();
|
|
976 node->definition = false;
|
|
977 node->analyzed = false;
|
|
978 node->cpp_implicit_alias = false;
|
|
979 }
|
|
980 else if (!node->alias
|
|
981 && node->definition
|
|
982 && node->get_availability () <= AVAIL_INTERPOSABLE)
|
|
983 {
|
|
984 if ((cnode = dyn_cast <cgraph_node *> (node)) != NULL)
|
|
985 cnode->reset ();
|
|
986 else
|
|
987 {
|
|
988 node->analyzed = node->definition = false;
|
|
989 node->remove_all_references ();
|
|
990 }
|
|
991 }
|
|
992 }
|
|
993
|
|
994 if (!(cnode = dyn_cast <cgraph_node *> (node))
|
|
995 || !cnode->clone_of
|
|
996 || cnode->clone_of->decl != cnode->decl)
|
|
997 {
|
|
998 /* Builtins are not merged via decl merging. It is however
|
|
999 possible that tree merging unified the declaration. We
|
|
1000 do not want duplicate entries in symbol table. */
|
|
1001 if (cnode && DECL_BUILT_IN (node->decl)
|
|
1002 && (cnode2 = cgraph_node::get (node->decl))
|
|
1003 && cnode2 != cnode)
|
|
1004 lto_cgraph_replace_node (cnode2, cnode);
|
|
1005
|
|
1006 /* The user defined assembler variables are also not unified by their
|
|
1007 symbol name (since it is irrelevant), but we need to unify symbol
|
|
1008 nodes if tree merging occurred. */
|
|
1009 if ((vnode = dyn_cast <varpool_node *> (node))
|
|
1010 && DECL_HARD_REGISTER (vnode->decl)
|
|
1011 && (node2 = symtab_node::get (vnode->decl))
|
|
1012 && node2 != node)
|
|
1013 lto_varpool_replace_node (dyn_cast <varpool_node *> (node2),
|
|
1014 vnode);
|
|
1015
|
|
1016
|
|
1017 /* Abstract functions may have duplicated cgraph nodes attached;
|
|
1018 remove them. */
|
|
1019 else if (cnode && DECL_ABSTRACT_P (cnode->decl)
|
|
1020 && (cnode2 = cgraph_node::get (node->decl))
|
|
1021 && cnode2 != cnode)
|
|
1022 cnode2->remove ();
|
|
1023
|
|
1024 node->decl->decl_with_vis.symtab_node = node;
|
|
1025 }
|
|
1026 }
|
|
1027 }
|
|
1028 }
|
|
1029
|
|
1030 /* Virtual tables may matter for code generation even if they are not
|
|
1031 directly refernced by the code because they may be used for devirtualizaiton.
|
|
1032 For this reason it is important to merge even virtual tables that have no
|
|
1033 associated symbol table entries. Without doing so we lose optimization
|
|
1034 oppurtunities by losing track of the vtable constructor.
|
|
1035 FIXME: we probably ought to introduce explicit symbol table entries for
|
|
1036 those before streaming. */
|
|
1037
|
|
1038 tree
|
|
1039 lto_symtab_prevailing_virtual_decl (tree decl)
|
|
1040 {
|
|
1041 if (DECL_ABSTRACT_P (decl))
|
|
1042 return decl;
|
|
1043 gcc_checking_assert (!type_in_anonymous_namespace_p (DECL_CONTEXT (decl))
|
|
1044 && DECL_ASSEMBLER_NAME_SET_P (decl));
|
|
1045
|
|
1046 symtab_node *n = symtab_node::get_for_asmname
|
|
1047 (DECL_ASSEMBLER_NAME (decl));
|
|
1048 while (n && ((!DECL_EXTERNAL (n->decl) && !TREE_PUBLIC (n->decl))
|
|
1049 || !DECL_VIRTUAL_P (n->decl)))
|
|
1050 n = n->next_sharing_asm_name;
|
|
1051 if (n)
|
|
1052 {
|
|
1053 /* Merge decl state in both directions, we may still end up using
|
|
1054 the other decl. */
|
|
1055 TREE_ADDRESSABLE (n->decl) |= TREE_ADDRESSABLE (decl);
|
|
1056 TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (n->decl);
|
|
1057
|
|
1058 if (TREE_CODE (decl) == FUNCTION_DECL)
|
|
1059 {
|
|
1060 /* Merge decl state in both directions, we may still end up using
|
|
1061 the other decl. */
|
|
1062 DECL_POSSIBLY_INLINED (n->decl) |= DECL_POSSIBLY_INLINED (decl);
|
|
1063 DECL_POSSIBLY_INLINED (decl) |= DECL_POSSIBLY_INLINED (n->decl);
|
|
1064 }
|
|
1065 lto_symtab_prevail_decl (n->decl, decl);
|
|
1066 decl = n->decl;
|
|
1067 }
|
|
1068 else
|
|
1069 symtab_node::get_create (decl);
|
|
1070
|
|
1071 return decl;
|
|
1072 }
|