OSDN Git Service

2009-10-15 Andrew Pinski <andrew_pinski@playstation.sony.com>
[pf3gnuchains/gcc-fork.git] / gcc / lto-symtab.c
1 /* LTO symbol table.
2    Copyright 2009 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 "toplev.h"
25 #include "tree.h"
26 #include "gimple.h"
27 #include "ggc.h"        /* lambda.h needs this */
28 #include "lambda.h"     /* gcd */
29 #include "hashtab.h"
30 #include "plugin-api.h"
31 #include "lto-streamer.h"
32
33 /* Vector to keep track of external variables we've seen so far.  */
34 VEC(tree,gc) *lto_global_var_decls;
35
36 /* Symbol table entry.  */
37
38 struct GTY(()) lto_symtab_entry_def
39 {
40   /* The symbol table entry key, an IDENTIFIER.  */
41   tree id;
42   /* The symbol table entry, a DECL.  */
43   tree decl;
44   /* LTO file-data and symbol resolution for this decl.  */
45   struct lto_file_decl_data * GTY((skip (""))) file_data;
46   enum ld_plugin_symbol_resolution resolution;
47   /* Pointer to the next entry with the same key.  Before decl merging
48      this links all symbols from the different TUs.  After decl merging
49      this links merged but incompatible decls, thus all prevailing ones
50      remaining.  */
51   struct lto_symtab_entry_def *next;
52 };
53 typedef struct lto_symtab_entry_def *lto_symtab_entry_t;
54
55 /* A poor man's symbol table. This hashes identifier to prevailing DECL
56    if there is one. */
57
58 static GTY ((if_marked ("lto_symtab_entry_marked_p"),
59              param_is (struct lto_symtab_entry_def)))
60   htab_t lto_symtab_identifiers;
61
62 /* Return the hash value of an lto_symtab_entry_t object pointed to by P.  */
63
64 static hashval_t
65 lto_symtab_entry_hash (const void *p)
66 {
67   const struct lto_symtab_entry_def *base =
68     (const struct lto_symtab_entry_def *) p;
69   return htab_hash_string (IDENTIFIER_POINTER (base->id));
70 }
71
72 /* Return non-zero if P1 and P2 points to lto_symtab_entry_def structs
73    corresponding to the same symbol.  */
74
75 static int
76 lto_symtab_entry_eq (const void *p1, const void *p2)
77 {
78   const struct lto_symtab_entry_def *base1 =
79      (const struct lto_symtab_entry_def *) p1;
80   const struct lto_symtab_entry_def *base2 =
81      (const struct lto_symtab_entry_def *) p2;
82   return (base1->id == base2->id);
83 }
84
85 /* Returns non-zero if P points to an lto_symtab_entry_def struct that needs
86    to be marked for GC.  */ 
87
88 static int
89 lto_symtab_entry_marked_p (const void *p)
90 {
91   const struct lto_symtab_entry_def *base =
92      (const struct lto_symtab_entry_def *) p;
93
94   /* Keep this only if the decl or the chain is marked.  */
95   return (ggc_marked_p (base->decl)
96           || (base->next && ggc_marked_p (base->next)));
97 }
98
99 /* Lazily initialize resolution hash tables.  */
100
101 static void
102 lto_symtab_maybe_init_hash_table (void)
103 {
104   if (lto_symtab_identifiers)
105     return;
106
107   lto_symtab_identifiers =
108     htab_create_ggc (1021, lto_symtab_entry_hash,
109                      lto_symtab_entry_eq, NULL);
110 }
111
112 /* Registers DECL with the LTO symbol table as having resolution RESOLUTION
113    and read from FILE_DATA. */
114
115 void
116 lto_symtab_register_decl (tree decl,
117                           ld_plugin_symbol_resolution_t resolution,
118                           struct lto_file_decl_data *file_data)
119 {
120   lto_symtab_entry_t new_entry;
121   void **slot;
122
123   /* Check that declarations reaching this function do not have
124      properties inconsistent with having external linkage.  If any of
125      these asertions fail, then the object file reader has failed to
126      detect these cases and issue appropriate error messages.  */
127   gcc_assert (decl
128               && TREE_PUBLIC (decl)
129               && (TREE_CODE (decl) == VAR_DECL
130                   || TREE_CODE (decl) == FUNCTION_DECL)
131               && DECL_ASSEMBLER_NAME_SET_P (decl));
132   if (TREE_CODE (decl) == VAR_DECL
133       && DECL_INITIAL (decl))
134     gcc_assert (!DECL_EXTERNAL (decl)
135                 || (TREE_STATIC (decl) && TREE_READONLY (decl)));
136   if (TREE_CODE (decl) == FUNCTION_DECL)
137     gcc_assert (!DECL_ABSTRACT (decl));
138
139   new_entry = GGC_CNEW (struct lto_symtab_entry_def);
140   new_entry->id = DECL_ASSEMBLER_NAME (decl);
141   new_entry->decl = decl;
142   new_entry->resolution = resolution;
143   new_entry->file_data = file_data;
144
145   lto_symtab_maybe_init_hash_table ();
146   slot = htab_find_slot (lto_symtab_identifiers, new_entry, INSERT);
147   new_entry->next = (lto_symtab_entry_t) *slot;
148   *slot = new_entry;
149 }
150
151 /* Get the lto_symtab_entry_def struct associated with ID
152    if there is one.  */
153
154 static lto_symtab_entry_t
155 lto_symtab_get (tree id)
156 {
157   struct lto_symtab_entry_def temp;
158   void **slot;
159
160   lto_symtab_maybe_init_hash_table ();
161   temp.id = id;
162   slot = htab_find_slot (lto_symtab_identifiers, &temp, NO_INSERT);
163   return slot ? (lto_symtab_entry_t) *slot : NULL;
164 }
165
166 /* Get the linker resolution for DECL.  */
167
168 enum ld_plugin_symbol_resolution
169 lto_symtab_get_resolution (tree decl)
170 {
171   lto_symtab_entry_t e;
172
173   gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
174
175   e = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
176   while (e && e->decl != decl)
177     e = e->next;
178   if (!e)
179     return LDPR_UNKNOWN;
180
181   return e->resolution;
182 }
183
184
185 static bool maybe_merge_incomplete_and_complete_type (tree, tree);
186
187 /* Try to merge an incomplete type INCOMPLETE with a complete type
188    COMPLETE of same kinds.
189    Return true if they were merged, false otherwise.  */
190
191 static bool
192 merge_incomplete_and_complete_type (tree incomplete, tree complete)
193 {
194   /* For merging array types do some extra sanity checking.  */
195   if (TREE_CODE (incomplete) == ARRAY_TYPE
196       && !maybe_merge_incomplete_and_complete_type (TREE_TYPE (incomplete),
197                                                     TREE_TYPE (complete))
198       && !gimple_types_compatible_p (TREE_TYPE (incomplete),
199                                      TREE_TYPE (complete)))
200     return false;
201
202   /* ??? Ideally we would do this by means of a common canonical type, but
203      that's difficult as we do not have links from the canonical type
204      back to all its children.  */
205   gimple_force_type_merge (incomplete, complete);
206
207   return true;
208 }
209
210 /* Try to merge a maybe complete / incomplete type pair TYPE1 and TYPE2.
211    Return true if they were merged, false otherwise.  */
212
213 static bool
214 maybe_merge_incomplete_and_complete_type (tree type1, tree type2)
215 {
216   bool res = false;
217
218   if (TREE_CODE (type1) != TREE_CODE (type2))
219     return false;
220
221   if (!COMPLETE_TYPE_P (type1) && COMPLETE_TYPE_P (type2))
222     res = merge_incomplete_and_complete_type (type1, type2);
223   else if (COMPLETE_TYPE_P (type1) && !COMPLETE_TYPE_P (type2))
224     res = merge_incomplete_and_complete_type (type2, type1);
225
226   /* Recurse on pointer targets.  */
227   if (!res
228       && POINTER_TYPE_P (type1)
229       && POINTER_TYPE_P (type2))
230     res = maybe_merge_incomplete_and_complete_type (TREE_TYPE (type1),
231                                                     TREE_TYPE (type2));
232
233   return res;
234 }
235
236 /* Replace the cgraph node NODE with PREVAILING_NODE in the cgraph, merging
237    all edges and removing the old node.  */
238
239 static void
240 lto_cgraph_replace_node (struct cgraph_node *node,
241                          struct cgraph_node *prevailing_node)
242 {
243   struct cgraph_edge *e, *next;
244
245   /* Merge node flags.  */
246   if (node->needed)
247     cgraph_mark_needed_node (prevailing_node);
248   if (node->reachable)
249     cgraph_mark_reachable_node (prevailing_node);
250   if (node->address_taken)
251     {
252       gcc_assert (!prevailing_node->global.inlined_to);
253       cgraph_mark_address_taken_node (prevailing_node);
254     }
255
256   /* Redirect all incoming edges.  */
257   for (e = node->callers; e; e = next)
258     {
259       next = e->next_caller;
260       cgraph_redirect_edge_callee (e, prevailing_node);
261     }
262
263   /* There are not supposed to be any outgoing edges from a node we
264      replace.  Still this can happen for multiple instances of weak
265      functions.  */
266   for (e = node->callees; e; e = next)
267     {
268       next = e->next_callee;
269       cgraph_remove_edge (e);
270     }
271
272   /* Finally remove the replaced node.  */
273   cgraph_remove_node (node);
274 }
275
276 /* Merge two variable or function symbol table entries PREVAILING and ENTRY.
277    Return false if the symbols are not fully compatible and a diagnostic
278    should be emitted.  */
279
280 static bool
281 lto_symtab_merge (lto_symtab_entry_t prevailing, lto_symtab_entry_t entry)
282 {
283   tree prevailing_decl = prevailing->decl;
284   tree decl = entry->decl;
285   tree prevailing_type, type;
286   struct cgraph_node *node;
287
288   /* Merge decl state in both directions, we may still end up using
289      the new decl.  */
290   TREE_ADDRESSABLE (prevailing_decl) |= TREE_ADDRESSABLE (decl);
291   TREE_ADDRESSABLE (decl) |= TREE_ADDRESSABLE (prevailing_decl);
292
293   /* Replace a cgraph node of entry with the prevailing one.  */
294   if (TREE_CODE (decl) == FUNCTION_DECL
295       && (node = cgraph_get_node (decl)) != NULL)
296     lto_cgraph_replace_node (node, cgraph_get_node (prevailing_decl));
297
298   /* The linker may ask us to combine two incompatible symbols.
299      Detect this case and notify the caller of required diagnostics.  */
300
301   if (TREE_CODE (decl) == FUNCTION_DECL)
302     {
303       if (!gimple_types_compatible_p (TREE_TYPE (prevailing_decl),
304                                       TREE_TYPE (decl)))
305         /* If we don't have a merged type yet...sigh.  The linker
306            wouldn't complain if the types were mismatched, so we
307            probably shouldn't either.  Just use the type from
308            whichever decl appears to be associated with the
309            definition.  If for some odd reason neither decl is, the
310            older one wins.  */
311         (void) 0;
312
313       return true;
314     }
315
316   /* Now we exclusively deal with VAR_DECLs.  */
317
318   /* Handle external declarations with incomplete type or pointed-to
319      incomplete types by forcefully merging the types.
320      ???  In principle all types involved in the two decls should
321      be merged forcefully, for example without considering type or
322      field names.  */
323   prevailing_type = TREE_TYPE (prevailing_decl);
324   type = TREE_TYPE (decl);
325
326   /* If the types are structurally equivalent we can use the knowledge
327      that both bind to the same symbol to complete incomplete types
328      of external declarations or of pointer targets.
329      ???  We should apply this recursively to aggregate members here
330      and get rid of the completion in gimple_types_compatible_p.  */
331   if (DECL_EXTERNAL (prevailing_decl) || DECL_EXTERNAL (decl))
332     maybe_merge_incomplete_and_complete_type (prevailing_type, type);
333   else if (POINTER_TYPE_P (prevailing_type)
334            && POINTER_TYPE_P (type))
335     maybe_merge_incomplete_and_complete_type (TREE_TYPE (prevailing_type),
336                                               TREE_TYPE (type));
337
338   /* We can tolerate differences in type qualification, the
339      qualification of the prevailing definition will prevail.  */
340   prevailing_type = TYPE_MAIN_VARIANT (TREE_TYPE (prevailing_decl));
341   type = TYPE_MAIN_VARIANT (TREE_TYPE (decl));
342   if (!gimple_types_compatible_p (prevailing_type, type))
343     return false;
344
345   /* ???  We might want to emit a warning here if type qualification
346      differences were spotted.  Do not do this unconditionally though.  */
347
348   /* There is no point in comparing too many details of the decls here.
349      The type compatibility checks or the completing of types has properly
350      dealt with most issues.  */
351
352   /* The following should all not invoke fatal errors as in non-LTO
353      mode the linker wouldn't complain either.  Just emit warnings.  */
354
355   /* Report a warning if user-specified alignments do not match.  */
356   if ((DECL_USER_ALIGN (prevailing_decl) && DECL_USER_ALIGN (decl))
357       && DECL_ALIGN (prevailing_decl) < DECL_ALIGN (decl))
358     return false;
359
360   return true;
361 }
362
363 /* Return true if the symtab entry E can be replaced by another symtab
364    entry.  */
365
366 static bool
367 lto_symtab_resolve_replaceable_p (lto_symtab_entry_t e)
368 {
369   if (DECL_EXTERNAL (e->decl)
370       || DECL_COMDAT (e->decl)
371       || DECL_WEAK (e->decl))
372     return true;
373
374   if (TREE_CODE (e->decl) == VAR_DECL)
375     return (DECL_COMMON (e->decl)
376             || (!flag_no_common && !DECL_INITIAL (e->decl)));
377
378   return false;
379 }
380
381 /* Return true if the symtab entry E can be the prevailing one.  */
382
383 static bool
384 lto_symtab_resolve_can_prevail_p (lto_symtab_entry_t e)
385 {
386   struct cgraph_node *node;
387
388   if (!TREE_STATIC (e->decl))
389     return false;
390
391   /* For functions we need a non-discarded body.  */
392   if (TREE_CODE (e->decl) == FUNCTION_DECL)
393     return ((node = cgraph_get_node (e->decl))
394             && node->analyzed);
395
396   /* A variable should have a size.  */
397   else if (TREE_CODE (e->decl) == VAR_DECL)
398     return (DECL_SIZE (e->decl) != NULL_TREE
399             /* The C++ frontend retains TREE_STATIC on the declaration
400                of foo_ in struct Foo { static Foo *foo_; }; but it is
401                not a definition.  g++.dg/lto/20090315_0.C.  */
402             && !DECL_EXTERNAL (e->decl));
403
404   gcc_unreachable ();
405 }
406
407 /* Resolve the symbol with the candidates in the chain *SLOT and store
408    their resolutions.  */
409
410 static void
411 lto_symtab_resolve_symbols (void **slot)
412 {
413   lto_symtab_entry_t e = (lto_symtab_entry_t) *slot;
414   lto_symtab_entry_t prevailing = NULL;
415
416   /* If the chain is already resolved there is nothing to do.  */
417   if (e->resolution != LDPR_UNKNOWN)
418     return;
419
420   /* Find the single non-replaceable prevailing symbol and
421      diagnose ODR violations.  */
422   for (; e; e = e->next)
423     {
424       if (!lto_symtab_resolve_can_prevail_p (e))
425         {
426           e->resolution = LDPR_RESOLVED_IR;
427           continue;
428         }
429
430       /* Set a default resolution - the final prevailing one will get
431          adjusted later.  */
432       e->resolution = LDPR_PREEMPTED_IR;
433       if (!lto_symtab_resolve_replaceable_p (e))
434         {
435           if (prevailing)
436             {
437               error_at (DECL_SOURCE_LOCATION (e->decl),
438                         "%qD has already been defined", e->decl);
439               inform (DECL_SOURCE_LOCATION (prevailing->decl),
440                       "previously defined here");
441             }
442           prevailing = e;
443         }
444     }
445   if (prevailing)
446     goto found;
447
448   /* Do a second round choosing one from the replaceable prevailing decls.  */
449   for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
450     {
451       if (e->resolution != LDPR_PREEMPTED_IR)
452         continue;
453
454       /* Choose the first function that can prevail as prevailing.  */
455       if (TREE_CODE (e->decl) == FUNCTION_DECL)
456         {
457           prevailing = e;
458           break;
459         }
460
461       /* From variables that can prevail choose the largest one.  */
462       if (!prevailing
463           || tree_int_cst_lt (DECL_SIZE (prevailing->decl),
464                               DECL_SIZE (e->decl)))
465         prevailing = e;
466     }
467
468   if (!prevailing)
469     return;
470
471 found:
472   if (TREE_CODE (prevailing->decl) == VAR_DECL
473       && TREE_READONLY (prevailing->decl))
474     prevailing->resolution = LDPR_PREVAILING_DEF_IRONLY;
475   else
476     prevailing->resolution = LDPR_PREVAILING_DEF;
477 }
478
479 /* Merge all decls in the symbol table chain to the prevailing decl and
480    issue diagnostics about type mismatches.  */
481
482 static void
483 lto_symtab_merge_decls_2 (void **slot)
484 {
485   lto_symtab_entry_t prevailing, e;
486   VEC(tree, heap) *mismatches = NULL;
487   unsigned i;
488   tree decl;
489   bool diagnosed_p = false;
490
491   /* Nothing to do for a single entry.  */
492   prevailing = (lto_symtab_entry_t) *slot;
493   if (!prevailing->next)
494     return;
495
496   /* Try to merge each entry with the prevailing one.  */
497   for (e = prevailing->next; e; e = e->next)
498     {
499       if (!lto_symtab_merge (prevailing, e))
500         VEC_safe_push (tree, heap, mismatches, e->decl);
501     }
502   if (VEC_empty (tree, mismatches))
503     return;
504
505   /* Diagnose all mismatched re-declarations.  */
506   for (i = 0; VEC_iterate (tree, mismatches, i, decl); ++i)
507     {
508       if (!gimple_types_compatible_p (TREE_TYPE (prevailing->decl),
509                                       TREE_TYPE (decl)))
510         diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
511                                    "type of %qD does not match original "
512                                    "declaration", decl);
513
514       else if ((DECL_USER_ALIGN (prevailing->decl) && DECL_USER_ALIGN (decl))
515                && DECL_ALIGN (prevailing->decl) < DECL_ALIGN (decl))
516         {
517           diagnosed_p |= warning_at (DECL_SOURCE_LOCATION (decl), 0,
518                                      "alignment of %qD is bigger than "
519                                      "original declaration", decl);
520         }
521     }
522   if (diagnosed_p)
523     inform (DECL_SOURCE_LOCATION (prevailing->decl),
524             "previously declared here");
525
526   VEC_free (tree, heap, mismatches);
527 }
528
529 /* Helper to process the decl chain for the symbol table entry *SLOT.  */
530
531 static int
532 lto_symtab_merge_decls_1 (void **slot, void *data ATTRIBUTE_UNUSED)
533 {
534   lto_symtab_entry_t e, prevailing;
535   bool diagnosed_p = false;
536
537   /* Compute the symbol resolutions.  This is a no-op when using the
538      linker plugin.  */
539   lto_symtab_resolve_symbols (slot);
540
541   /* Find the prevailing decl.  */
542   for (prevailing = (lto_symtab_entry_t) *slot;
543        prevailing
544        && prevailing->resolution != LDPR_PREVAILING_DEF_IRONLY
545        && prevailing->resolution != LDPR_PREVAILING_DEF;
546        prevailing = prevailing->next)
547     ;
548
549   /* Assert it's the only one.  */
550   if (prevailing)
551     for (e = prevailing->next; e; e = e->next)
552       gcc_assert (e->resolution != LDPR_PREVAILING_DEF_IRONLY
553                   && e->resolution != LDPR_PREVAILING_DEF);
554
555   /* If there's not a prevailing symbol yet it's an external reference.
556      Happens a lot during ltrans.  Choose the first symbol with a
557      cgraph or a varpool node.  */
558   if (!prevailing)
559     {
560       prevailing = (lto_symtab_entry_t) *slot;
561       /* For functions choose one with a cgraph node.  */
562       if (TREE_CODE (prevailing->decl) == FUNCTION_DECL)
563         while (!cgraph_get_node (prevailing->decl)
564                && prevailing->next)
565           prevailing = prevailing->next;
566       /* We do not stream varpool nodes, so the first decl has to
567          be good enough for now.
568          ???  For QOI choose a variable with readonly initializer
569          if there is one.  This matches C++
570          struct Foo { static const int i = 1; }; without a real
571          definition.  */
572       if (TREE_CODE (prevailing->decl) == VAR_DECL)
573         while (!(TREE_READONLY (prevailing->decl)
574                  && DECL_INITIAL (prevailing->decl))
575                && prevailing->next)
576           prevailing = prevailing->next;
577     }
578
579   /* Move it first in the list.  */
580   if ((lto_symtab_entry_t) *slot != prevailing)
581     {
582       for (e = (lto_symtab_entry_t) *slot; e->next != prevailing; e = e->next)
583         ;
584       e->next = prevailing->next;
585       prevailing->next = (lto_symtab_entry_t) *slot;
586       *slot = (void *) prevailing;
587     }
588
589   /* Record the prevailing variable.  */
590   if (TREE_CODE (prevailing->decl) == VAR_DECL)
591     VEC_safe_push (tree, gc, lto_global_var_decls, prevailing->decl);
592
593   /* Diagnose mismatched objects.  */
594   for (e = prevailing->next; e; e = e->next)
595     {
596       if (TREE_CODE (prevailing->decl) == TREE_CODE (e->decl))
597         continue;
598
599       switch (TREE_CODE (prevailing->decl))
600         {
601         case VAR_DECL:
602           gcc_assert (TREE_CODE (e->decl) == FUNCTION_DECL);
603           error_at (DECL_SOURCE_LOCATION (e->decl),
604                     "variable %qD redeclared as function", prevailing->decl);
605           break;
606
607         case FUNCTION_DECL:
608           gcc_assert (TREE_CODE (e->decl) == VAR_DECL);
609           error_at (DECL_SOURCE_LOCATION (e->decl),
610                     "function %qD redeclared as variable", prevailing->decl);
611           break;
612
613         default:
614           gcc_unreachable ();
615         }
616
617       diagnosed_p = true;
618     }
619   if (diagnosed_p)
620       inform (DECL_SOURCE_LOCATION (prevailing->decl),
621               "previously declared here");
622
623   /* Register and adjust types of the entries.  */
624   for (e = (lto_symtab_entry_t) *slot; e; e = e->next)
625     TREE_TYPE (e->decl) = gimple_register_type (TREE_TYPE (e->decl));
626
627   /* Merge the chain to the single prevailing decl and diagnose
628      mismatches.  */
629   lto_symtab_merge_decls_2 (slot);
630
631   /* Drop all but the prevailing decl from the symtab.  */
632   prevailing->next = NULL;
633
634   return 1;
635 }
636
637 /* Resolve and merge all symbol table chains to a prevailing decl.  */
638
639 void
640 lto_symtab_merge_decls (void)
641 {
642   lto_symtab_maybe_init_hash_table ();
643   htab_traverse (lto_symtab_identifiers, lto_symtab_merge_decls_1, NULL);
644 }
645
646
647 /* Given the decl DECL, return the prevailing decl with the same name. */
648
649 tree
650 lto_symtab_prevailing_decl (tree decl)
651 {
652   lto_symtab_entry_t ret;
653
654   /* Builtins and local symbols are their own prevailing decl.  */
655   if (!TREE_PUBLIC (decl) || is_builtin_fn (decl))
656     return decl;
657
658   /* DECL_ABSTRACTs are their own prevailng decl.  */
659   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT (decl))
660     return decl;
661
662   /* Ensure DECL_ASSEMBLER_NAME will not set assembler name.  */
663   gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
664
665   /* Walk through the list of candidates and return the one we merged to.  */
666   ret = lto_symtab_get (DECL_ASSEMBLER_NAME (decl));
667   if (!ret)
668     return NULL_TREE;
669
670   return ret->decl;
671 }
672
673 /* Remove any storage used to store resolution of DECL.  */
674
675 void
676 lto_symtab_clear_resolution (tree decl)
677 {
678   struct lto_symtab_entry_def temp;
679   lto_symtab_entry_t head;
680   void **slot;
681
682   if (!TREE_PUBLIC (decl))
683     return;
684
685   /* LTO FIXME: There should be no DECL_ABSTRACT in the middle end. */
686   if (TREE_CODE (decl) == FUNCTION_DECL && DECL_ABSTRACT (decl))
687     return;
688
689   gcc_assert (DECL_ASSEMBLER_NAME_SET_P (decl));
690
691   lto_symtab_maybe_init_hash_table ();
692   temp.id = DECL_ASSEMBLER_NAME (decl);
693   slot = htab_find_slot (lto_symtab_identifiers, &temp, NO_INSERT);
694   if (!*slot)
695     return;
696
697   head = (lto_symtab_entry_t) *slot;
698   if (head->decl == decl)
699     {
700       if (head->next)
701         {
702           *slot = head->next;
703           head->next = NULL;
704         }
705       else
706         htab_remove_elt (lto_symtab_identifiers, &temp);
707     }
708   else
709     {
710       lto_symtab_entry_t e;
711       while (head->next && head->next->decl != decl)
712         head = head->next;
713       if (head->next)
714         {
715           e = head->next;
716           head->next = e->next;
717           e->next = NULL;
718         }
719     }
720 }
721
722 #include "gt-lto-symtab.h"