xref: /llvm-project-15.0.7/lld/ELF/Symbols.cpp (revision 4129890d)
1 //===- Symbols.cpp --------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Symbols.h"
10 #include "InputFiles.h"
11 #include "InputSection.h"
12 #include "OutputSections.h"
13 #include "SyntheticSections.h"
14 #include "Target.h"
15 #include "Writer.h"
16 #include "lld/Common/ErrorHandler.h"
17 #include "lld/Common/Strings.h"
18 #include <cstring>
19 
20 using namespace llvm;
21 using namespace llvm::object;
22 using namespace llvm::ELF;
23 using namespace lld;
24 using namespace lld::elf;
25 
26 std::string lld::toString(const elf::Symbol &sym) {
27   StringRef name = sym.getName();
28   std::string ret = demangle(name, config->demangle);
29 
30   const char *suffix = sym.getVersionSuffix();
31   if (*suffix == '@')
32     ret += suffix;
33   return ret;
34 }
35 
36 Defined *ElfSym::bss;
37 Defined *ElfSym::etext1;
38 Defined *ElfSym::etext2;
39 Defined *ElfSym::edata1;
40 Defined *ElfSym::edata2;
41 Defined *ElfSym::end1;
42 Defined *ElfSym::end2;
43 Defined *ElfSym::globalOffsetTable;
44 Defined *ElfSym::mipsGp;
45 Defined *ElfSym::mipsGpDisp;
46 Defined *ElfSym::mipsLocalGp;
47 Defined *ElfSym::relaIpltStart;
48 Defined *ElfSym::relaIpltEnd;
49 Defined *ElfSym::riscvGlobalPointer;
50 Defined *ElfSym::tlsModuleBase;
51 DenseMap<const Symbol *, std::pair<const InputFile *, const InputFile *>>
52     elf::backwardReferences;
53 SmallVector<std::tuple<std::string, const InputFile *, const Symbol &>, 0>
54     elf::whyExtract;
55 SmallVector<SymbolAux, 0> elf::symAux;
56 
57 static uint64_t getSymVA(const Symbol &sym, int64_t addend) {
58   switch (sym.kind()) {
59   case Symbol::DefinedKind: {
60     auto &d = cast<Defined>(sym);
61     SectionBase *isec = d.section;
62 
63     // This is an absolute symbol.
64     if (!isec)
65       return d.value;
66 
67     assert(isec != &InputSection::discarded);
68 
69     uint64_t offset = d.value;
70 
71     // An object in an SHF_MERGE section might be referenced via a
72     // section symbol (as a hack for reducing the number of local
73     // symbols).
74     // Depending on the addend, the reference via a section symbol
75     // refers to a different object in the merge section.
76     // Since the objects in the merge section are not necessarily
77     // contiguous in the output, the addend can thus affect the final
78     // VA in a non-linear way.
79     // To make this work, we incorporate the addend into the section
80     // offset (and zero out the addend for later processing) so that
81     // we find the right object in the section.
82     if (d.isSection())
83       offset += addend;
84 
85     // In the typical case, this is actually very simple and boils
86     // down to adding together 3 numbers:
87     // 1. The address of the output section.
88     // 2. The offset of the input section within the output section.
89     // 3. The offset within the input section (this addition happens
90     //    inside InputSection::getOffset).
91     //
92     // If you understand the data structures involved with this next
93     // line (and how they get built), then you have a pretty good
94     // understanding of the linker.
95     uint64_t va = isec->getVA(offset);
96     if (d.isSection())
97       va -= addend;
98 
99     // MIPS relocatable files can mix regular and microMIPS code.
100     // Linker needs to distinguish such code. To do so microMIPS
101     // symbols has the `STO_MIPS_MICROMIPS` flag in the `st_other`
102     // field. Unfortunately, the `MIPS::relocate()` method has
103     // a symbol value only. To pass type of the symbol (regular/microMIPS)
104     // to that routine as well as other places where we write
105     // a symbol value as-is (.dynamic section, `Elf_Ehdr::e_entry`
106     // field etc) do the same trick as compiler uses to mark microMIPS
107     // for CPU - set the less-significant bit.
108     if (config->emachine == EM_MIPS && isMicroMips() &&
109         ((sym.stOther & STO_MIPS_MICROMIPS) || sym.needsCopy))
110       va |= 1;
111 
112     if (d.isTls() && !config->relocatable) {
113       // Use the address of the TLS segment's first section rather than the
114       // segment's address, because segment addresses aren't initialized until
115       // after sections are finalized. (e.g. Measuring the size of .rela.dyn
116       // for Android relocation packing requires knowing TLS symbol addresses
117       // during section finalization.)
118       if (!Out::tlsPhdr || !Out::tlsPhdr->firstSec)
119         fatal(toString(d.file) +
120               " has an STT_TLS symbol but doesn't have an SHF_TLS section");
121       return va - Out::tlsPhdr->firstSec->addr;
122     }
123     return va;
124   }
125   case Symbol::SharedKind:
126   case Symbol::UndefinedKind:
127     return 0;
128   case Symbol::LazyObjectKind:
129     llvm_unreachable("lazy symbol reached writer");
130   case Symbol::CommonKind:
131     llvm_unreachable("common symbol reached writer");
132   case Symbol::PlaceholderKind:
133     llvm_unreachable("placeholder symbol reached writer");
134   }
135   llvm_unreachable("invalid symbol kind");
136 }
137 
138 uint64_t Symbol::getVA(int64_t addend) const {
139   return getSymVA(*this, addend) + addend;
140 }
141 
142 uint64_t Symbol::getGotVA() const {
143   if (gotInIgot)
144     return in.igotPlt->getVA() + getGotPltOffset();
145   return in.got->getVA() + getGotOffset();
146 }
147 
148 uint64_t Symbol::getGotOffset() const {
149   return getGotIdx() * target->gotEntrySize;
150 }
151 
152 uint64_t Symbol::getGotPltVA() const {
153   if (isInIplt)
154     return in.igotPlt->getVA() + getGotPltOffset();
155   return in.gotPlt->getVA() + getGotPltOffset();
156 }
157 
158 uint64_t Symbol::getGotPltOffset() const {
159   if (isInIplt)
160     return getPltIdx() * target->gotEntrySize;
161   return (getPltIdx() + target->gotPltHeaderEntriesNum) * target->gotEntrySize;
162 }
163 
164 uint64_t Symbol::getPltVA() const {
165   uint64_t outVA = isInIplt
166                        ? in.iplt->getVA() + getPltIdx() * target->ipltEntrySize
167                        : in.plt->getVA() + in.plt->headerSize +
168                              getPltIdx() * target->pltEntrySize;
169 
170   // While linking microMIPS code PLT code are always microMIPS
171   // code. Set the less-significant bit to track that fact.
172   // See detailed comment in the `getSymVA` function.
173   if (config->emachine == EM_MIPS && isMicroMips())
174     outVA |= 1;
175   return outVA;
176 }
177 
178 uint64_t Symbol::getSize() const {
179   if (const auto *dr = dyn_cast<Defined>(this))
180     return dr->size;
181   return cast<SharedSymbol>(this)->size;
182 }
183 
184 OutputSection *Symbol::getOutputSection() const {
185   if (auto *s = dyn_cast<Defined>(this)) {
186     if (auto *sec = s->section)
187       return sec->getOutputSection();
188     return nullptr;
189   }
190   return nullptr;
191 }
192 
193 // If a symbol name contains '@', the characters after that is
194 // a symbol version name. This function parses that.
195 void Symbol::parseSymbolVersion() {
196   // Return if localized by a local: pattern in a version script.
197   if (versionId == VER_NDX_LOCAL)
198     return;
199   StringRef s = getName();
200   size_t pos = s.find('@');
201   if (pos == StringRef::npos)
202     return;
203   StringRef verstr = s.substr(pos + 1);
204 
205   // Truncate the symbol name so that it doesn't include the version string.
206   nameSize = pos;
207 
208   if (verstr.empty())
209     return;
210 
211   // If this is not in this DSO, it is not a definition.
212   if (!isDefined())
213     return;
214 
215   // '@@' in a symbol name means the default version.
216   // It is usually the most recent one.
217   bool isDefault = (verstr[0] == '@');
218   if (isDefault)
219     verstr = verstr.substr(1);
220 
221   for (const VersionDefinition &ver : namedVersionDefs()) {
222     if (ver.name != verstr)
223       continue;
224 
225     if (isDefault)
226       versionId = ver.id;
227     else
228       versionId = ver.id | VERSYM_HIDDEN;
229     return;
230   }
231 
232   // It is an error if the specified version is not defined.
233   // Usually version script is not provided when linking executable,
234   // but we may still want to override a versioned symbol from DSO,
235   // so we do not report error in this case. We also do not error
236   // if the symbol has a local version as it won't be in the dynamic
237   // symbol table.
238   if (config->shared && versionId != VER_NDX_LOCAL)
239     error(toString(file) + ": symbol " + s + " has undefined version " +
240           verstr);
241 }
242 
243 void Symbol::extract() const {
244   if (file->lazy) {
245     file->lazy = false;
246     parseFile(file);
247   }
248 }
249 
250 uint8_t Symbol::computeBinding() const {
251   if ((visibility != STV_DEFAULT && visibility != STV_PROTECTED) ||
252       versionId == VER_NDX_LOCAL)
253     return STB_LOCAL;
254   if (binding == STB_GNU_UNIQUE && !config->gnuUnique)
255     return STB_GLOBAL;
256   return binding;
257 }
258 
259 bool Symbol::includeInDynsym() const {
260   if (computeBinding() == STB_LOCAL)
261     return false;
262   if (!isDefined() && !isCommon())
263     // This should unconditionally return true, unfortunately glibc -static-pie
264     // expects undefined weak symbols not to exist in .dynsym, e.g.
265     // __pthread_mutex_lock reference in _dl_add_to_namespace_list,
266     // __pthread_initialize_minimal reference in csu/libc-start.c.
267     return !(isUndefWeak() && config->noDynamicLinker);
268 
269   return exportDynamic || inDynamicList;
270 }
271 
272 // Print out a log message for --trace-symbol.
273 void elf::printTraceSymbol(const Symbol &sym, StringRef name) {
274   std::string s;
275   if (sym.isUndefined())
276     s = ": reference to ";
277   else if (sym.isLazy())
278     s = ": lazy definition of ";
279   else if (sym.isShared())
280     s = ": shared definition of ";
281   else if (sym.isCommon())
282     s = ": common definition of ";
283   else
284     s = ": definition of ";
285 
286   message(toString(sym.file) + s + name);
287 }
288 
289 static void recordWhyExtract(const InputFile *reference,
290                              const InputFile &extracted, const Symbol &sym) {
291   whyExtract.emplace_back(toString(reference), &extracted, sym);
292 }
293 
294 void elf::maybeWarnUnorderableSymbol(const Symbol *sym) {
295   if (!config->warnSymbolOrdering)
296     return;
297 
298   // If UnresolvedPolicy::Ignore is used, no "undefined symbol" error/warning
299   // is emitted. It makes sense to not warn on undefined symbols.
300   //
301   // Note, ld.bfd --symbol-ordering-file= does not warn on undefined symbols,
302   // but we don't have to be compatible here.
303   if (sym->isUndefined() &&
304       config->unresolvedSymbols == UnresolvedPolicy::Ignore)
305     return;
306 
307   const InputFile *file = sym->file;
308   auto *d = dyn_cast<Defined>(sym);
309 
310   auto report = [&](StringRef s) { warn(toString(file) + s + sym->getName()); };
311 
312   if (sym->isUndefined())
313     report(": unable to order undefined symbol: ");
314   else if (sym->isShared())
315     report(": unable to order shared symbol: ");
316   else if (d && !d->section)
317     report(": unable to order absolute symbol: ");
318   else if (d && isa<OutputSection>(d->section))
319     report(": unable to order synthetic symbol: ");
320   else if (d && !d->section->isLive())
321     report(": unable to order discarded symbol: ");
322 }
323 
324 // Returns true if a symbol can be replaced at load-time by a symbol
325 // with the same name defined in other ELF executable or DSO.
326 bool elf::computeIsPreemptible(const Symbol &sym) {
327   assert(!sym.isLocal() || sym.isPlaceholder());
328 
329   // Only symbols with default visibility that appear in dynsym can be
330   // preempted. Symbols with protected visibility cannot be preempted.
331   if (!sym.includeInDynsym() || sym.visibility != STV_DEFAULT)
332     return false;
333 
334   // At this point copy relocations have not been created yet, so any
335   // symbol that is not defined locally is preemptible.
336   if (!sym.isDefined())
337     return true;
338 
339   if (!config->shared)
340     return false;
341 
342   // If -Bsymbolic or --dynamic-list is specified, or -Bsymbolic-functions is
343   // specified and the symbol is STT_FUNC, the symbol is preemptible iff it is
344   // in the dynamic list. -Bsymbolic-non-weak-functions is a non-weak subset of
345   // -Bsymbolic-functions.
346   if (config->symbolic ||
347       (config->bsymbolic == BsymbolicKind::Functions && sym.isFunc()) ||
348       (config->bsymbolic == BsymbolicKind::NonWeakFunctions && sym.isFunc() &&
349        sym.binding != STB_WEAK))
350     return sym.inDynamicList;
351   return true;
352 }
353 
354 void elf::reportBackrefs() {
355   for (auto &it : backwardReferences) {
356     const Symbol &sym = *it.first;
357     std::string to = toString(it.second.second);
358     // Some libraries have known problems and can cause noise. Filter them out
359     // with --warn-backrefs-exclude=. to may look like *.o or *.a(*.o).
360     bool exclude = false;
361     for (const llvm::GlobPattern &pat : config->warnBackrefsExclude)
362       if (pat.match(to)) {
363         exclude = true;
364         break;
365       }
366     if (!exclude)
367       warn("backward reference detected: " + sym.getName() + " in " +
368            toString(it.second.first) + " refers to " + to);
369   }
370 }
371 
372 static uint8_t getMinVisibility(uint8_t va, uint8_t vb) {
373   if (va == STV_DEFAULT)
374     return vb;
375   if (vb == STV_DEFAULT)
376     return va;
377   return std::min(va, vb);
378 }
379 
380 // Merge symbol properties.
381 //
382 // When we have many symbols of the same name, we choose one of them,
383 // and that's the result of symbol resolution. However, symbols that
384 // were not chosen still affect some symbol properties.
385 void Symbol::mergeProperties(const Symbol &other) {
386   if (other.exportDynamic)
387     exportDynamic = true;
388 
389   // DSO symbols do not affect visibility in the output.
390   if (!other.isShared())
391     visibility = getMinVisibility(visibility, other.visibility);
392 }
393 
394 void Symbol::resolve(const Symbol &other) {
395   mergeProperties(other);
396 
397   if (isPlaceholder()) {
398     replace(other);
399     return;
400   }
401 
402   switch (other.kind()) {
403   case Symbol::UndefinedKind:
404     resolveUndefined(cast<Undefined>(other));
405     break;
406   case Symbol::CommonKind:
407     resolveCommon(cast<CommonSymbol>(other));
408     break;
409   case Symbol::DefinedKind:
410     resolveDefined(cast<Defined>(other));
411     break;
412   case Symbol::LazyObjectKind:
413     resolveLazy(cast<LazyObject>(other));
414     break;
415   case Symbol::SharedKind:
416     resolveShared(cast<SharedSymbol>(other));
417     break;
418   case Symbol::PlaceholderKind:
419     llvm_unreachable("bad symbol kind");
420   }
421 }
422 
423 void Symbol::resolveUndefined(const Undefined &other) {
424   // An undefined symbol with non default visibility must be satisfied
425   // in the same DSO.
426   //
427   // If this is a non-weak defined symbol in a discarded section, override the
428   // existing undefined symbol for better error message later.
429   if ((isShared() && other.visibility != STV_DEFAULT) ||
430       (isUndefined() && other.binding != STB_WEAK && other.discardedSecIdx)) {
431     replace(other);
432     return;
433   }
434 
435   if (traced)
436     printTraceSymbol(other, getName());
437 
438   if (isLazy()) {
439     // An undefined weak will not extract archive members. See comment on Lazy
440     // in Symbols.h for the details.
441     if (other.binding == STB_WEAK) {
442       binding = STB_WEAK;
443       type = other.type;
444       return;
445     }
446 
447     // Do extra check for --warn-backrefs.
448     //
449     // --warn-backrefs is an option to prevent an undefined reference from
450     // extracting an archive member written earlier in the command line. It can
451     // be used to keep compatibility with GNU linkers to some degree. I'll
452     // explain the feature and why you may find it useful in this comment.
453     //
454     // lld's symbol resolution semantics is more relaxed than traditional Unix
455     // linkers. For example,
456     //
457     //   ld.lld foo.a bar.o
458     //
459     // succeeds even if bar.o contains an undefined symbol that has to be
460     // resolved by some object file in foo.a. Traditional Unix linkers don't
461     // allow this kind of backward reference, as they visit each file only once
462     // from left to right in the command line while resolving all undefined
463     // symbols at the moment of visiting.
464     //
465     // In the above case, since there's no undefined symbol when a linker visits
466     // foo.a, no files are pulled out from foo.a, and because the linker forgets
467     // about foo.a after visiting, it can't resolve undefined symbols in bar.o
468     // that could have been resolved otherwise.
469     //
470     // That lld accepts more relaxed form means that (besides it'd make more
471     // sense) you can accidentally write a command line or a build file that
472     // works only with lld, even if you have a plan to distribute it to wider
473     // users who may be using GNU linkers. With --warn-backrefs, you can detect
474     // a library order that doesn't work with other Unix linkers.
475     //
476     // The option is also useful to detect cyclic dependencies between static
477     // archives. Again, lld accepts
478     //
479     //   ld.lld foo.a bar.a
480     //
481     // even if foo.a and bar.a depend on each other. With --warn-backrefs, it is
482     // handled as an error.
483     //
484     // Here is how the option works. We assign a group ID to each file. A file
485     // with a smaller group ID can pull out object files from an archive file
486     // with an equal or greater group ID. Otherwise, it is a reverse dependency
487     // and an error.
488     //
489     // A file outside --{start,end}-group gets a fresh ID when instantiated. All
490     // files within the same --{start,end}-group get the same group ID. E.g.
491     //
492     //   ld.lld A B --start-group C D --end-group E
493     //
494     // A forms group 0. B form group 1. C and D (including their member object
495     // files) form group 2. E forms group 3. I think that you can see how this
496     // group assignment rule simulates the traditional linker's semantics.
497     bool backref = config->warnBackrefs && other.file &&
498                    file->groupId < other.file->groupId;
499     extract();
500 
501     if (!config->whyExtract.empty())
502       recordWhyExtract(other.file, *file, *this);
503 
504     // We don't report backward references to weak symbols as they can be
505     // overridden later.
506     //
507     // A traditional linker does not error for -ldef1 -lref -ldef2 (linking
508     // sandwich), where def2 may or may not be the same as def1. We don't want
509     // to warn for this case, so dismiss the warning if we see a subsequent lazy
510     // definition. this->file needs to be saved because in the case of LTO it
511     // may be reset to nullptr or be replaced with a file named lto.tmp.
512     if (backref && !isWeak())
513       backwardReferences.try_emplace(this, std::make_pair(other.file, file));
514     return;
515   }
516 
517   // Undefined symbols in a SharedFile do not change the binding.
518   if (isa_and_nonnull<SharedFile>(other.file))
519     return;
520 
521   if (isUndefined() || isShared()) {
522     // The binding will be weak if there is at least one reference and all are
523     // weak. The binding has one opportunity to change to weak: if the first
524     // reference is weak.
525     if (other.binding != STB_WEAK || !referenced)
526       binding = other.binding;
527   }
528 }
529 
530 // Compare two symbols. Return 1 if the new symbol should win, -1 if
531 // the new symbol should lose, or 0 if there is a conflict.
532 int Symbol::compare(const Symbol *other) const {
533   assert(other->isDefined() || other->isCommon());
534 
535   if (!isDefined() && !isCommon())
536     return 1;
537 
538   // .symver foo,foo@@VER unfortunately creates two defined symbols: foo and
539   // foo@@VER. In GNU ld, if foo and foo@@VER are in the same file, foo is
540   // ignored. In our implementation, when this is foo, this->getName() may still
541   // contain @@, return 1 in this case as well.
542   if (file == other->file) {
543     if (other->getName().contains("@@"))
544       return 1;
545     if (getName().contains("@@"))
546       return -1;
547   }
548 
549   if (other->isWeak())
550     return -1;
551 
552   if (isWeak())
553     return 1;
554 
555   if (isCommon() && other->isCommon()) {
556     if (config->warnCommon)
557       warn("multiple common of " + getName());
558     return 0;
559   }
560 
561   if (isCommon()) {
562     if (config->warnCommon)
563       warn("common " + getName() + " is overridden");
564     return 1;
565   }
566 
567   if (other->isCommon()) {
568     if (config->warnCommon)
569       warn("common " + getName() + " is overridden");
570     return -1;
571   }
572 
573   return 0;
574 }
575 
576 void elf::reportDuplicate(const Symbol &sym, InputFile *newFile,
577                           InputSectionBase *errSec, uint64_t errOffset) {
578   if (config->allowMultipleDefinition)
579     return;
580   const Defined *d = cast<Defined>(&sym);
581   if (!d->section || !errSec) {
582     error("duplicate symbol: " + toString(sym) + "\n>>> defined in " +
583           toString(sym.file) + "\n>>> defined in " + toString(newFile));
584     return;
585   }
586 
587   // Construct and print an error message in the form of:
588   //
589   //   ld.lld: error: duplicate symbol: foo
590   //   >>> defined at bar.c:30
591   //   >>>            bar.o (/home/alice/src/bar.o)
592   //   >>> defined at baz.c:563
593   //   >>>            baz.o in archive libbaz.a
594   auto *sec1 = cast<InputSectionBase>(d->section);
595   std::string src1 = sec1->getSrcMsg(sym, d->value);
596   std::string obj1 = sec1->getObjMsg(d->value);
597   std::string src2 = errSec->getSrcMsg(sym, errOffset);
598   std::string obj2 = errSec->getObjMsg(errOffset);
599 
600   std::string msg = "duplicate symbol: " + toString(sym) + "\n>>> defined at ";
601   if (!src1.empty())
602     msg += src1 + "\n>>>            ";
603   msg += obj1 + "\n>>> defined at ";
604   if (!src2.empty())
605     msg += src2 + "\n>>>            ";
606   msg += obj2;
607   error(msg);
608 }
609 
610 void Symbol::checkDuplicate(const Defined &other) const {
611   if (compare(&other) == 0)
612     reportDuplicate(*this, other.file,
613                     dyn_cast_or_null<InputSectionBase>(other.section),
614                     other.value);
615 }
616 
617 void Symbol::resolveCommon(const CommonSymbol &other) {
618   int cmp = compare(&other);
619   if (cmp < 0)
620     return;
621 
622   if (cmp > 0) {
623     if (auto *s = dyn_cast<SharedSymbol>(this)) {
624       // Increase st_size if the shared symbol has a larger st_size. The shared
625       // symbol may be created from common symbols. The fact that some object
626       // files were linked into a shared object first should not change the
627       // regular rule that picks the largest st_size.
628       uint64_t size = s->size;
629       replace(other);
630       if (size > cast<CommonSymbol>(this)->size)
631         cast<CommonSymbol>(this)->size = size;
632     } else {
633       replace(other);
634     }
635     return;
636   }
637 
638   CommonSymbol *oldSym = cast<CommonSymbol>(this);
639 
640   oldSym->alignment = std::max(oldSym->alignment, other.alignment);
641   if (oldSym->size < other.size) {
642     oldSym->file = other.file;
643     oldSym->size = other.size;
644   }
645 }
646 
647 void Symbol::resolveDefined(const Defined &other) {
648   int cmp = compare(&other);
649   if (cmp > 0)
650     replace(other);
651 }
652 
653 void Symbol::resolveLazy(const LazyObject &other) {
654   // For common objects, we want to look for global or weak definitions that
655   // should be extracted as the canonical definition instead.
656   if (isCommon() && elf::config->fortranCommon) {
657     if (auto *loSym = dyn_cast<LazyObject>(&other)) {
658       if (loSym->file->shouldExtractForCommon(getName())) {
659         backwardReferences.erase(this);
660         replace(other);
661         other.extract();
662         return;
663       }
664     }
665   }
666 
667   if (!isUndefined()) {
668     // See the comment in resolveUndefined().
669     if (isDefined())
670       backwardReferences.erase(this);
671     return;
672   }
673 
674   // An undefined weak will not extract archive members. See comment on Lazy in
675   // Symbols.h for the details.
676   if (isWeak()) {
677     uint8_t ty = type;
678     replace(other);
679     type = ty;
680     binding = STB_WEAK;
681     return;
682   }
683 
684   const InputFile *oldFile = file;
685   other.extract();
686   if (!config->whyExtract.empty())
687     recordWhyExtract(oldFile, *file, *this);
688 }
689 
690 void Symbol::resolveShared(const SharedSymbol &other) {
691   if (isCommon()) {
692     // See the comment in resolveCommon() above.
693     if (other.size > cast<CommonSymbol>(this)->size)
694       cast<CommonSymbol>(this)->size = other.size;
695     return;
696   }
697   if (visibility == STV_DEFAULT && (isUndefined() || isLazy())) {
698     // An undefined symbol with non default visibility must be satisfied
699     // in the same DSO.
700     uint8_t bind = binding;
701     replace(other);
702     binding = bind;
703   } else if (traced)
704     printTraceSymbol(other, getName());
705 }
706