Fix versions of copied symbols.
[external/binutils.git] / gold / resolve.cc
1 // resolve.cc -- symbol resolution for gold
2
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
5
6 // This file is part of gold.
7
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
12
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
22
23 #include "gold.h"
24
25 #include "elfcpp.h"
26 #include "target.h"
27 #include "object.h"
28 #include "symtab.h"
29
30 namespace gold
31 {
32
33 // Symbol methods used in this file.
34
35 // Override the fields in Symbol.
36
37 template<int size, bool big_endian>
38 void
39 Symbol::override_base(const elfcpp::Sym<size, big_endian>& sym,
40                       Object* object, const char* version)
41 {
42   gold_assert(this->source_ == FROM_OBJECT);
43   this->u_.from_object.object = object;
44   if (version != NULL && this->version() != version)
45     {
46       gold_assert(this->version() == NULL);
47       this->version_ = version;
48     }
49   // FIXME: Handle SHN_XINDEX.
50   this->u_.from_object.shndx = sym.get_st_shndx();
51   this->type_ = sym.get_st_type();
52   this->binding_ = sym.get_st_bind();
53   this->visibility_ = sym.get_st_visibility();
54   this->nonvis_ = sym.get_st_nonvis();
55   if (object->is_dynamic())
56     this->in_dyn_ = true;
57   else
58     this->in_reg_ = true;
59 }
60
61 // Override the fields in Sized_symbol.
62
63 template<int size>
64 template<bool big_endian>
65 void
66 Sized_symbol<size>::override(const elfcpp::Sym<size, big_endian>& sym,
67                              Object* object, const char* version)
68 {
69   this->override_base(sym, object, version);
70   this->value_ = sym.get_st_value();
71   this->symsize_ = sym.get_st_size();
72 }
73
74 // Override TOSYM with symbol FROMSYM, defined in OBJECT, with version
75 // VERSION.  This handles all aliases of TOSYM.
76
77 template<int size, bool big_endian>
78 void
79 Symbol_table::override(Sized_symbol<size>* tosym,
80                        const elfcpp::Sym<size, big_endian>& fromsym,
81                        Object* object, const char* version)
82 {
83   tosym->override(fromsym, object, version);
84   if (tosym->has_alias())
85     {
86       Symbol* sym = this->weak_aliases_[tosym];
87       gold_assert(sym != NULL);
88       Sized_symbol<size>* ssym;
89       ssym = this->get_sized_symbol SELECT_SIZE_NAME(size) (sym
90                                                             SELECT_SIZE(size));
91       do
92         {
93           ssym->override(fromsym, object, version);
94           sym = this->weak_aliases_[ssym];
95           gold_assert(sym != NULL);
96           ssym = this->get_sized_symbol SELECT_SIZE_NAME(size) (
97                                                 sym SELECT_SIZE(size));
98         }
99       while (ssym != tosym);
100     }
101 }
102
103 // The resolve functions build a little code for each symbol.
104 // Bit 0: 0 for global, 1 for weak.
105 // Bit 1: 0 for regular object, 1 for shared object
106 // Bits 2-3: 0 for normal, 1 for undefined, 2 for common
107 // This gives us values from 0 to 11.
108
109 static const int global_or_weak_shift = 0;
110 static const unsigned int global_flag = 0 << global_or_weak_shift;
111 static const unsigned int weak_flag = 1 << global_or_weak_shift;
112
113 static const int regular_or_dynamic_shift = 1;
114 static const unsigned int regular_flag = 0 << regular_or_dynamic_shift;
115 static const unsigned int dynamic_flag = 1 << regular_or_dynamic_shift;
116
117 static const int def_undef_or_common_shift = 2;
118 static const unsigned int def_flag = 0 << def_undef_or_common_shift;
119 static const unsigned int undef_flag = 1 << def_undef_or_common_shift;
120 static const unsigned int common_flag = 2 << def_undef_or_common_shift;
121
122 // Resolve a symbol.  This is called the second and subsequent times
123 // we see a symbol.  TO is the pre-existing symbol.  SYM is the new
124 // symbol, seen in OBJECT.  VERSION of the version of SYM.
125
126 template<int size, bool big_endian>
127 void
128 Symbol_table::resolve(Sized_symbol<size>* to,
129                       const elfcpp::Sym<size, big_endian>& sym,
130                       Object* object, const char* version)
131 {
132   if (object->target()->has_resolve())
133     {
134       Sized_target<size, big_endian>* sized_target;
135       sized_target = object->sized_target
136                      SELECT_SIZE_ENDIAN_NAME(size, big_endian) (
137                          SELECT_SIZE_ENDIAN_ONLY(size, big_endian));
138       sized_target->resolve(to, sym, object, version);
139       return;
140     }
141
142   if (!object->is_dynamic())
143     {
144       // Record that we've seen this symbol in a regular object.
145       to->set_in_reg();
146     }
147   else
148     {
149       // Record that we've seen this symbol in a dynamic object.
150       to->set_in_dyn();
151     }
152
153   unsigned int frombits;
154   switch (sym.get_st_bind())
155     {
156     case elfcpp::STB_GLOBAL:
157       frombits = global_flag;
158       break;
159
160     case elfcpp::STB_WEAK:
161       frombits = weak_flag;
162       break;
163
164     case elfcpp::STB_LOCAL:
165       gold_error(_("%s: invalid STB_LOCAL symbol %s in external symbols"),
166                  object->name().c_str(), to->name());
167       frombits = global_flag;
168       break;
169
170     default:
171       gold_error(_("%s: unsupported symbol binding %d for symbol %s"),
172                  object->name().c_str(),
173                  static_cast<int>(sym.get_st_bind()), to->name());
174       frombits = global_flag;
175       break;
176     }
177
178   if (!object->is_dynamic())
179     frombits |= regular_flag;
180   else
181     frombits |= dynamic_flag;
182
183   switch (sym.get_st_shndx())
184     {
185     case elfcpp::SHN_UNDEF:
186       frombits |= undef_flag;
187       break;
188
189     case elfcpp::SHN_COMMON:
190       frombits |= common_flag;
191       break;
192
193     default:
194       if (sym.get_st_type() == elfcpp::STT_COMMON)
195         frombits |= common_flag;
196       else
197         frombits |= def_flag;
198       break;
199     }
200
201   bool adjust_common_sizes;
202   if (Symbol_table::should_override(to, frombits, object,
203                                     &adjust_common_sizes))
204     {
205       typename Sized_symbol<size>::Size_type tosize = to->symsize();
206
207       this->override(to, sym, object, version);
208
209       if (adjust_common_sizes && tosize > to->symsize())
210         to->set_symsize(tosize);
211     }
212   else
213     {
214       if (adjust_common_sizes && sym.get_st_size() > to->symsize())
215         to->set_symsize(sym.get_st_size());
216     }
217 }
218
219 // Handle the core of symbol resolution.  This is called with the
220 // existing symbol, TO, and a bitflag describing the new symbol.  This
221 // returns true if we should override the existing symbol with the new
222 // one, and returns false otherwise.  It sets *ADJUST_COMMON_SIZES to
223 // true if we should set the symbol size to the maximum of the TO and
224 // FROM sizes.  It handles error conditions.
225
226 bool
227 Symbol_table::should_override(const Symbol* to, unsigned int frombits,
228                               Object* object, bool* adjust_common_sizes)
229 {
230   *adjust_common_sizes = false;
231
232   unsigned int tobits;
233   switch (to->binding())
234     {
235     case elfcpp::STB_GLOBAL:
236       tobits = global_flag;
237       break;
238
239     case elfcpp::STB_WEAK:
240       tobits = weak_flag;
241       break;
242
243     case elfcpp::STB_LOCAL:
244       // We should only see externally visible symbols in the symbol
245       // table.
246       gold_unreachable();
247
248     default:
249       // Any target which wants to handle STB_LOOS, etc., needs to
250       // define a resolve method.
251       gold_unreachable();
252     }
253
254   if (to->source() == Symbol::FROM_OBJECT
255       && to->object()->is_dynamic())
256     tobits |= dynamic_flag;
257   else
258     tobits |= regular_flag;
259
260   switch (to->shndx())
261     {
262     case elfcpp::SHN_UNDEF:
263       tobits |= undef_flag;
264       break;
265
266     case elfcpp::SHN_COMMON:
267       tobits |= common_flag;
268       break;
269
270     default:
271       if (to->type() == elfcpp::STT_COMMON)
272         tobits |= common_flag;
273       else
274         tobits |= def_flag;
275       break;
276     }
277
278   // FIXME: Warn if either but not both of TO and SYM are STT_TLS.
279
280   // We use a giant switch table for symbol resolution.  This code is
281   // unwieldy, but: 1) it is efficient; 2) we definitely handle all
282   // cases; 3) it is easy to change the handling of a particular case.
283   // The alternative would be a series of conditionals, but it is easy
284   // to get the ordering wrong.  This could also be done as a table,
285   // but that is no easier to understand than this large switch
286   // statement.
287
288   // These are the values generated by the bit codes.
289   enum
290   {
291     DEF =              global_flag | regular_flag | def_flag,
292     WEAK_DEF =         weak_flag   | regular_flag | def_flag,
293     DYN_DEF =          global_flag | dynamic_flag | def_flag,
294     DYN_WEAK_DEF =     weak_flag   | dynamic_flag | def_flag,
295     UNDEF =            global_flag | regular_flag | undef_flag,
296     WEAK_UNDEF =       weak_flag   | regular_flag | undef_flag,
297     DYN_UNDEF =        global_flag | dynamic_flag | undef_flag,
298     DYN_WEAK_UNDEF =   weak_flag   | dynamic_flag | undef_flag,
299     COMMON =           global_flag | regular_flag | common_flag,
300     WEAK_COMMON =      weak_flag   | regular_flag | common_flag,
301     DYN_COMMON =       global_flag | dynamic_flag | common_flag,
302     DYN_WEAK_COMMON =  weak_flag   | dynamic_flag | common_flag
303   };
304
305   switch (tobits * 16 + frombits)
306     {
307     case DEF * 16 + DEF:
308       // Two definitions of the same symbol.
309       // FIXME: Do a better job of reporting locations.
310       gold_error(_("%s: multiple definition of %s"),
311                  object != NULL ? object->name().c_str() : _("command line"),
312                  to->name());
313       gold_error(_("%s: previous definition here"),
314                  (to->source() == Symbol::FROM_OBJECT
315                   ? to->object()->name().c_str()
316                   : _("command line")));
317       return false;
318
319     case WEAK_DEF * 16 + DEF:
320       // We've seen a weak definition, and now we see a strong
321       // definition.  In the original SVR4 linker, this was treated as
322       // a multiple definition error.  In the Solaris linker and the
323       // GNU linker, a weak definition followed by a regular
324       // definition causes the weak definition to be overridden.  We
325       // are currently compatible with the GNU linker.  In the future
326       // we should add a target specific option to change this.
327       // FIXME.
328       return true;
329
330     case DYN_DEF * 16 + DEF:
331     case DYN_WEAK_DEF * 16 + DEF:
332       // We've seen a definition in a dynamic object, and now we see a
333       // definition in a regular object.  The definition in the
334       // regular object overrides the definition in the dynamic
335       // object.
336       return true;
337
338     case UNDEF * 16 + DEF:
339     case WEAK_UNDEF * 16 + DEF:
340     case DYN_UNDEF * 16 + DEF:
341     case DYN_WEAK_UNDEF * 16 + DEF:
342       // We've seen an undefined reference, and now we see a
343       // definition.  We use the definition.
344       return true;
345
346     case COMMON * 16 + DEF:
347     case WEAK_COMMON * 16 + DEF:
348     case DYN_COMMON * 16 + DEF:
349     case DYN_WEAK_COMMON * 16 + DEF:
350       // We've seen a common symbol and now we see a definition.  The
351       // definition overrides.  FIXME: We should optionally issue, version a
352       // warning.
353       return true;
354
355     case DEF * 16 + WEAK_DEF:
356     case WEAK_DEF * 16 + WEAK_DEF:
357       // We've seen a definition and now we see a weak definition.  We
358       // ignore the new weak definition.
359       return false;
360
361     case DYN_DEF * 16 + WEAK_DEF:
362     case DYN_WEAK_DEF * 16 + WEAK_DEF:
363       // We've seen a dynamic definition and now we see a regular weak
364       // definition.  The regular weak definition overrides.
365       return true;
366
367     case UNDEF * 16 + WEAK_DEF:
368     case WEAK_UNDEF * 16 + WEAK_DEF:
369     case DYN_UNDEF * 16 + WEAK_DEF:
370     case DYN_WEAK_UNDEF * 16 + WEAK_DEF:
371       // A weak definition of a currently undefined symbol.
372       return true;
373
374     case COMMON * 16 + WEAK_DEF:
375     case WEAK_COMMON * 16 + WEAK_DEF:
376       // A weak definition does not override a common definition.
377       return false;
378
379     case DYN_COMMON * 16 + WEAK_DEF:
380     case DYN_WEAK_COMMON * 16 + WEAK_DEF:
381       // A weak definition does override a definition in a dynamic
382       // object.  FIXME: We should optionally issue a warning.
383       return true;
384
385     case DEF * 16 + DYN_DEF:
386     case WEAK_DEF * 16 + DYN_DEF:
387     case DYN_DEF * 16 + DYN_DEF:
388     case DYN_WEAK_DEF * 16 + DYN_DEF:
389       // Ignore a dynamic definition if we already have a definition.
390       return false;
391
392     case UNDEF * 16 + DYN_DEF:
393     case WEAK_UNDEF * 16 + DYN_DEF:
394     case DYN_UNDEF * 16 + DYN_DEF:
395     case DYN_WEAK_UNDEF * 16 + DYN_DEF:
396       // Use a dynamic definition if we have a reference.
397       return true;
398
399     case COMMON * 16 + DYN_DEF:
400     case WEAK_COMMON * 16 + DYN_DEF:
401     case DYN_COMMON * 16 + DYN_DEF:
402     case DYN_WEAK_COMMON * 16 + DYN_DEF:
403       // Ignore a dynamic definition if we already have a common
404       // definition.
405       return false;
406
407     case DEF * 16 + DYN_WEAK_DEF:
408     case WEAK_DEF * 16 + DYN_WEAK_DEF:
409     case DYN_DEF * 16 + DYN_WEAK_DEF:
410     case DYN_WEAK_DEF * 16 + DYN_WEAK_DEF:
411       // Ignore a weak dynamic definition if we already have a
412       // definition.
413       return false;
414
415     case UNDEF * 16 + DYN_WEAK_DEF:
416     case WEAK_UNDEF * 16 + DYN_WEAK_DEF:
417     case DYN_UNDEF * 16 + DYN_WEAK_DEF:
418     case DYN_WEAK_UNDEF * 16 + DYN_WEAK_DEF:
419       // Use a weak dynamic definition if we have a reference.
420       return true;
421
422     case COMMON * 16 + DYN_WEAK_DEF:
423     case WEAK_COMMON * 16 + DYN_WEAK_DEF:
424     case DYN_COMMON * 16 + DYN_WEAK_DEF:
425     case DYN_WEAK_COMMON * 16 + DYN_WEAK_DEF:
426       // Ignore a weak dynamic definition if we already have a common
427       // definition.
428       return false;
429
430     case DEF * 16 + UNDEF:
431     case WEAK_DEF * 16 + UNDEF:
432     case DYN_DEF * 16 + UNDEF:
433     case DYN_WEAK_DEF * 16 + UNDEF:
434     case UNDEF * 16 + UNDEF:
435       // A new undefined reference tells us nothing.
436       return false;
437
438     case WEAK_UNDEF * 16 + UNDEF:
439     case DYN_UNDEF * 16 + UNDEF:
440     case DYN_WEAK_UNDEF * 16 + UNDEF:
441       // A strong undef overrides a dynamic or weak undef.
442       return true;
443
444     case COMMON * 16 + UNDEF:
445     case WEAK_COMMON * 16 + UNDEF:
446     case DYN_COMMON * 16 + UNDEF:
447     case DYN_WEAK_COMMON * 16 + UNDEF:
448       // A new undefined reference tells us nothing.
449       return false;
450
451     case DEF * 16 + WEAK_UNDEF:
452     case WEAK_DEF * 16 + WEAK_UNDEF:
453     case DYN_DEF * 16 + WEAK_UNDEF:
454     case DYN_WEAK_DEF * 16 + WEAK_UNDEF:
455     case UNDEF * 16 + WEAK_UNDEF:
456     case WEAK_UNDEF * 16 + WEAK_UNDEF:
457     case DYN_UNDEF * 16 + WEAK_UNDEF:
458     case DYN_WEAK_UNDEF * 16 + WEAK_UNDEF:
459     case COMMON * 16 + WEAK_UNDEF:
460     case WEAK_COMMON * 16 + WEAK_UNDEF:
461     case DYN_COMMON * 16 + WEAK_UNDEF:
462     case DYN_WEAK_COMMON * 16 + WEAK_UNDEF:
463       // A new weak undefined reference tells us nothing.
464       return false;
465
466     case DEF * 16 + DYN_UNDEF:
467     case WEAK_DEF * 16 + DYN_UNDEF:
468     case DYN_DEF * 16 + DYN_UNDEF:
469     case DYN_WEAK_DEF * 16 + DYN_UNDEF:
470     case UNDEF * 16 + DYN_UNDEF:
471     case WEAK_UNDEF * 16 + DYN_UNDEF:
472     case DYN_UNDEF * 16 + DYN_UNDEF:
473     case DYN_WEAK_UNDEF * 16 + DYN_UNDEF:
474     case COMMON * 16 + DYN_UNDEF:
475     case WEAK_COMMON * 16 + DYN_UNDEF:
476     case DYN_COMMON * 16 + DYN_UNDEF:
477     case DYN_WEAK_COMMON * 16 + DYN_UNDEF:
478       // A new dynamic undefined reference tells us nothing.
479       return false;
480
481     case DEF * 16 + DYN_WEAK_UNDEF:
482     case WEAK_DEF * 16 + DYN_WEAK_UNDEF:
483     case DYN_DEF * 16 + DYN_WEAK_UNDEF:
484     case DYN_WEAK_DEF * 16 + DYN_WEAK_UNDEF:
485     case UNDEF * 16 + DYN_WEAK_UNDEF:
486     case WEAK_UNDEF * 16 + DYN_WEAK_UNDEF:
487     case DYN_UNDEF * 16 + DYN_WEAK_UNDEF:
488     case DYN_WEAK_UNDEF * 16 + DYN_WEAK_UNDEF:
489     case COMMON * 16 + DYN_WEAK_UNDEF:
490     case WEAK_COMMON * 16 + DYN_WEAK_UNDEF:
491     case DYN_COMMON * 16 + DYN_WEAK_UNDEF:
492     case DYN_WEAK_COMMON * 16 + DYN_WEAK_UNDEF:
493       // A new weak dynamic undefined reference tells us nothing.
494       return false;
495
496     case DEF * 16 + COMMON:
497       // A common symbol does not override a definition.
498       return false;
499
500     case WEAK_DEF * 16 + COMMON:
501     case DYN_DEF * 16 + COMMON:
502     case DYN_WEAK_DEF * 16 + COMMON:
503       // A common symbol does override a weak definition or a dynamic
504       // definition.
505       return true;
506
507     case UNDEF * 16 + COMMON:
508     case WEAK_UNDEF * 16 + COMMON:
509     case DYN_UNDEF * 16 + COMMON:
510     case DYN_WEAK_UNDEF * 16 + COMMON:
511       // A common symbol is a definition for a reference.
512       return true;
513
514     case COMMON * 16 + COMMON:
515       // Set the size to the maximum.
516       *adjust_common_sizes = true;
517       return false;
518
519     case WEAK_COMMON * 16 + COMMON:
520       // I'm not sure just what a weak common symbol means, but
521       // presumably it can be overridden by a regular common symbol.
522       return true;
523
524     case DYN_COMMON * 16 + COMMON:
525     case DYN_WEAK_COMMON * 16 + COMMON:
526       // Use the real common symbol, but adjust the size if necessary.
527       *adjust_common_sizes = true;
528       return true;
529
530     case DEF * 16 + WEAK_COMMON:
531     case WEAK_DEF * 16 + WEAK_COMMON:
532     case DYN_DEF * 16 + WEAK_COMMON:
533     case DYN_WEAK_DEF * 16 + WEAK_COMMON:
534       // Whatever a weak common symbol is, it won't override a
535       // definition.
536       return false;
537
538     case UNDEF * 16 + WEAK_COMMON:
539     case WEAK_UNDEF * 16 + WEAK_COMMON:
540     case DYN_UNDEF * 16 + WEAK_COMMON:
541     case DYN_WEAK_UNDEF * 16 + WEAK_COMMON:
542       // A weak common symbol is better than an undefined symbol.
543       return true;
544
545     case COMMON * 16 + WEAK_COMMON:
546     case WEAK_COMMON * 16 + WEAK_COMMON:
547     case DYN_COMMON * 16 + WEAK_COMMON:
548     case DYN_WEAK_COMMON * 16 + WEAK_COMMON:
549       // Ignore a weak common symbol in the presence of a real common
550       // symbol.
551       return false;
552
553     case DEF * 16 + DYN_COMMON:
554     case WEAK_DEF * 16 + DYN_COMMON:
555     case DYN_DEF * 16 + DYN_COMMON:
556     case DYN_WEAK_DEF * 16 + DYN_COMMON:
557       // Ignore a dynamic common symbol in the presence of a
558       // definition.
559       return false;
560
561     case UNDEF * 16 + DYN_COMMON:
562     case WEAK_UNDEF * 16 + DYN_COMMON:
563     case DYN_UNDEF * 16 + DYN_COMMON:
564     case DYN_WEAK_UNDEF * 16 + DYN_COMMON:
565       // A dynamic common symbol is a definition of sorts.
566       return true;
567
568     case COMMON * 16 + DYN_COMMON:
569     case WEAK_COMMON * 16 + DYN_COMMON:
570     case DYN_COMMON * 16 + DYN_COMMON:
571     case DYN_WEAK_COMMON * 16 + DYN_COMMON:
572       // Set the size to the maximum.
573       *adjust_common_sizes = true;
574       return false;
575
576     case DEF * 16 + DYN_WEAK_COMMON:
577     case WEAK_DEF * 16 + DYN_WEAK_COMMON:
578     case DYN_DEF * 16 + DYN_WEAK_COMMON:
579     case DYN_WEAK_DEF * 16 + DYN_WEAK_COMMON:
580       // A common symbol is ignored in the face of a definition.
581       return false;
582
583     case UNDEF * 16 + DYN_WEAK_COMMON:
584     case WEAK_UNDEF * 16 + DYN_WEAK_COMMON:
585     case DYN_UNDEF * 16 + DYN_WEAK_COMMON:
586     case DYN_WEAK_UNDEF * 16 + DYN_WEAK_COMMON:
587       // I guess a weak common symbol is better than a definition.
588       return true;
589
590     case COMMON * 16 + DYN_WEAK_COMMON:
591     case WEAK_COMMON * 16 + DYN_WEAK_COMMON:
592     case DYN_COMMON * 16 + DYN_WEAK_COMMON:
593     case DYN_WEAK_COMMON * 16 + DYN_WEAK_COMMON:
594       // Set the size to the maximum.
595       *adjust_common_sizes = true;
596       return false;
597
598     default:
599       gold_unreachable();
600     }
601 }
602
603 // A special case of should_override which is only called for a strong
604 // defined symbol from a regular object file.  This is used when
605 // defining special symbols.
606
607 bool
608 Symbol_table::should_override_with_special(const Symbol* to)
609 {
610   bool adjust_common_sizes;
611   unsigned int frombits = global_flag | regular_flag | def_flag;
612   bool ret = Symbol_table::should_override(to, frombits, NULL,
613                                            &adjust_common_sizes);
614   gold_assert(!adjust_common_sizes);
615   return ret;
616 }
617
618 // Override symbol base with a special symbol.
619
620 void
621 Symbol::override_base_with_special(const Symbol* from)
622 {
623   gold_assert(this->name_ == from->name_ || this->has_alias());
624
625   this->source_ = from->source_;
626   switch (from->source_)
627     {
628     case FROM_OBJECT:
629       this->u_.from_object = from->u_.from_object;
630       break;
631     case IN_OUTPUT_DATA:
632       this->u_.in_output_data = from->u_.in_output_data;
633       break;
634     case IN_OUTPUT_SEGMENT:
635       this->u_.in_output_segment = from->u_.in_output_segment;
636       break;
637     case CONSTANT:
638       break;
639     default:
640       gold_unreachable();
641       break;
642     }
643
644   if (from->version_ != NULL && this->version_ != from->version_)
645     {
646       gold_assert(this->version_ == NULL);
647       this->version_ = from->version_;
648     }
649
650   this->type_ = from->type_;
651   this->binding_ = from->binding_;
652   this->visibility_ = from->visibility_;
653   this->nonvis_ = from->nonvis_;
654
655   // Special symbols are always considered to be regular symbols.
656   this->in_reg_ = true;
657
658   if (from->needs_dynsym_entry_)
659     this->needs_dynsym_entry_ = true;
660   if (from->needs_dynsym_value_)
661     this->needs_dynsym_value_ = true;
662
663   // We shouldn't see these flags.  If we do, we need to handle them
664   // somehow.
665   gold_assert(!from->is_target_special_ || this->is_target_special_);
666   gold_assert(!from->is_forwarder_);
667   gold_assert(!from->has_got_offset_);
668   gold_assert(!from->has_plt_offset_);
669   gold_assert(!from->has_warning_);
670   gold_assert(!from->is_copied_from_dynobj_);
671 }
672
673 // Override a symbol with a special symbol.
674
675 template<int size>
676 void
677 Sized_symbol<size>::override_with_special(const Sized_symbol<size>* from)
678 {
679   this->override_base_with_special(from);
680   this->value_ = from->value_;
681   this->symsize_ = from->symsize_;
682 }
683
684 // Override TOSYM with the special symbol FROMSYM.  This handles all
685 // aliases of TOSYM.
686
687 template<int size>
688 void
689 Symbol_table::override_with_special(Sized_symbol<size>* tosym,
690                                     const Sized_symbol<size>* fromsym)
691 {
692   tosym->override_with_special(fromsym);
693   if (tosym->has_alias())
694     {
695       Symbol* sym = this->weak_aliases_[tosym];
696       gold_assert(sym != NULL);
697       Sized_symbol<size>* ssym;
698       ssym = this->get_sized_symbol SELECT_SIZE_NAME(size) (sym
699                                                             SELECT_SIZE(size));
700       do
701         {
702           ssym->override_with_special(fromsym);
703           sym = this->weak_aliases_[ssym];
704           gold_assert(sym != NULL);
705           ssym = this->get_sized_symbol SELECT_SIZE_NAME(size) (
706                                                 sym SELECT_SIZE(size));
707         }
708       while (ssym != tosym);
709     }
710 }
711
712 // Instantiate the templates we need.  We could use the configure
713 // script to restrict this to only the ones needed for implemented
714 // targets.
715
716 #ifdef HAVE_TARGET_32_LITTLE
717 template
718 void
719 Symbol_table::resolve<32, false>(
720     Sized_symbol<32>* to,
721     const elfcpp::Sym<32, false>& sym,
722     Object* object,
723     const char* version);
724 #endif
725
726 #ifdef HAVE_TARGET_32_BIG
727 template
728 void
729 Symbol_table::resolve<32, true>(
730     Sized_symbol<32>* to,
731     const elfcpp::Sym<32, true>& sym,
732     Object* object,
733     const char* version);
734 #endif
735
736 #ifdef HAVE_TARGET_64_LITTLE
737 template
738 void
739 Symbol_table::resolve<64, false>(
740     Sized_symbol<64>* to,
741     const elfcpp::Sym<64, false>& sym,
742     Object* object,
743     const char* version);
744 #endif
745
746 #ifdef HAVE_TARGET_64_BIG
747 template
748 void
749 Symbol_table::resolve<64, true>(
750     Sized_symbol<64>* to,
751     const elfcpp::Sym<64, true>& sym,
752     Object* object,
753     const char* version);
754 #endif
755
756 #if defined(HAVE_TARGET_32_LITTLE) || defined(HAVE_TARGET_32_BIG)
757 template
758 void
759 Symbol_table::override_with_special<32>(Sized_symbol<32>*,
760                                         const Sized_symbol<32>*);
761 #endif
762
763 #if defined(HAVE_TARGET_64_LITTLE) || defined(HAVE_TARGET_64_BIG)
764 template
765 void
766 Symbol_table::override_with_special<64>(Sized_symbol<64>*,
767                                         const Sized_symbol<64>*);
768 #endif
769
770 } // End namespace gold.