1 //===- SymbolTable.cpp ----------------------------------------------------===//
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Symbol table is a bag of all known symbols. We put all symbols of
11 // all input files to the symbol table. The symbol table is basically
12 // a hash table with the logic to resolve symbol name conflicts using
15 //===----------------------------------------------------------------------===//
17 #include "SymbolTable.h"
19 #include "LinkerScript.h"
21 #include "SyntheticSections.h"
22 #include "lld/Common/ErrorHandler.h"
23 #include "lld/Common/Memory.h"
24 #include "lld/Common/Strings.h"
25 #include "llvm/ADT/STLExtras.h"
28 using namespace llvm::object;
29 using namespace llvm::ELF;
32 using namespace lld::elf;
34 SymbolTable *elf::Symtab;
36 static InputFile *getFirstElf() {
37 if (!ObjectFiles.empty())
38 return ObjectFiles[0];
39 if (!SharedFiles.empty())
40 return SharedFiles[0];
44 // All input object files must be for the same architecture
45 // (e.g. it does not make sense to link x86 object files with
46 // MIPS object files.) This function checks for that error.
47 static bool isCompatible(InputFile *F) {
48 if (!F->isElf() && !isa<BitcodeFile>(F))
51 if (F->EKind == Config->EKind && F->EMachine == Config->EMachine) {
52 if (Config->EMachine != EM_MIPS)
54 if (isMipsN32Abi(F) == Config->MipsN32Abi)
58 if (!Config->Emulation.empty())
59 error(toString(F) + " is incompatible with " + Config->Emulation);
61 error(toString(F) + " is incompatible with " + toString(getFirstElf()));
65 // Add symbols in File to the symbol table.
66 template <class ELFT> void SymbolTable::addFile(InputFile *File) {
67 if (!isCompatible(File))
71 if (auto *F = dyn_cast<BinaryFile>(File)) {
72 BinaryFiles.push_back(F);
78 if (auto *F = dyn_cast<ArchiveFile>(File)) {
84 if (auto *F = dyn_cast<LazyObjFile>(File)) {
90 message(toString(File));
93 if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
94 // DSOs are uniquified not by filename but by soname.
96 if (errorCount() || !SoNames.insert(F->SoName).second)
98 SharedFiles.push_back(F);
104 if (auto *F = dyn_cast<BitcodeFile>(File)) {
105 BitcodeFiles.push_back(F);
106 F->parse<ELFT>(ComdatGroups);
110 // Regular object file
111 ObjectFiles.push_back(File);
112 cast<ObjFile<ELFT>>(File)->parse(ComdatGroups);
115 // This function is where all the optimizations of link-time
116 // optimization happens. When LTO is in use, some input files are
117 // not in native object file format but in the LLVM bitcode format.
118 // This function compiles bitcode files into a few big native files
119 // using LLVM functions and replaces bitcode symbols with the results.
120 // Because all bitcode files that consist of a program are passed
121 // to the compiler at once, it can do whole-program optimization.
122 template <class ELFT> void SymbolTable::addCombinedLTOObject() {
123 if (BitcodeFiles.empty())
126 // Compile bitcode files and replace bitcode symbols.
127 LTO.reset(new BitcodeCompiler);
128 for (BitcodeFile *F : BitcodeFiles)
131 for (InputFile *File : LTO->compile()) {
132 DenseSet<CachedHashStringRef> DummyGroups;
133 auto *Obj = cast<ObjFile<ELFT>>(File);
134 Obj->parse(DummyGroups);
135 for (Symbol *Sym : Obj->getGlobalSymbols())
136 Sym->parseSymbolVersion();
137 ObjectFiles.push_back(File);
141 Defined *SymbolTable::addAbsolute(StringRef Name, uint8_t Visibility,
144 addRegular(Name, Visibility, STT_NOTYPE, 0, 0, Binding, nullptr, nullptr);
145 return cast<Defined>(Sym);
148 // Set a flag for --trace-symbol so that we can print out a log message
149 // if a new symbol with the same name is inserted into the symbol table.
150 void SymbolTable::trace(StringRef Name) {
151 SymMap.insert({CachedHashStringRef(Name), -1});
154 // Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM.
155 // Used to implement --wrap.
156 template <class ELFT> void SymbolTable::addSymbolWrap(StringRef Name) {
157 Symbol *Sym = find(Name);
160 Symbol *Real = addUndefined<ELFT>(Saver.save("__real_" + Name));
161 Symbol *Wrap = addUndefined<ELFT>(Saver.save("__wrap_" + Name));
162 WrappedSymbols.push_back({Sym, Real, Wrap});
164 // We want to tell LTO not to inline symbols to be overwritten
165 // because LTO doesn't know the final symbol contents after renaming.
166 Real->CanInline = false;
167 Sym->CanInline = false;
169 // Tell LTO not to eliminate these symbols.
170 Sym->IsUsedInRegularObj = true;
171 Wrap->IsUsedInRegularObj = true;
174 // Apply symbol renames created by -wrap. The renames are created
175 // before LTO in addSymbolWrap() to have a chance to inform LTO (if
176 // LTO is running) not to include these symbols in IPO. Now that the
177 // symbols are finalized, we can perform the replacement.
178 void SymbolTable::applySymbolWrap() {
179 // This function rotates 3 symbols:
181 // __real_sym becomes sym
182 // sym becomes __wrap_sym
183 // __wrap_sym becomes __real_sym
185 // The last part is special in that we don't want to change what references to
186 // __wrap_sym point to, we just want have __real_sym in the symbol table.
188 for (WrappedSymbol &W : WrappedSymbols) {
189 // First, make a copy of __real_sym.
190 Symbol *Real = nullptr;
191 if (W.Real->isDefined()) {
192 Real = (Symbol *)make<SymbolUnion>();
193 memcpy(Real, W.Real, sizeof(SymbolUnion));
196 // Replace __real_sym with sym and sym with __wrap_sym.
197 memcpy(W.Real, W.Sym, sizeof(SymbolUnion));
198 memcpy(W.Sym, W.Wrap, sizeof(SymbolUnion));
200 // We now have two copies of __wrap_sym. Drop one.
201 W.Wrap->IsUsedInRegularObj = false;
204 SymVector.push_back(Real);
208 static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
209 if (VA == STV_DEFAULT)
211 if (VB == STV_DEFAULT)
213 return std::min(VA, VB);
216 // Find an existing symbol or create and insert a new one.
217 std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name) {
218 // <name>@@<version> means the symbol is the default version. In that
219 // case <name>@@<version> will be used to resolve references to <name>.
221 // Since this is a hot path, the following string search code is
222 // optimized for speed. StringRef::find(char) is much faster than
223 // StringRef::find(StringRef).
224 size_t Pos = Name.find('@');
225 if (Pos != StringRef::npos && Pos + 1 < Name.size() && Name[Pos + 1] == '@')
226 Name = Name.take_front(Pos);
228 auto P = SymMap.insert({CachedHashStringRef(Name), (int)SymVector.size()});
229 int &SymIndex = P.first->second;
230 bool IsNew = P.second;
233 if (SymIndex == -1) {
234 SymIndex = SymVector.size();
235 IsNew = Traced = true;
240 Sym = (Symbol *)make<SymbolUnion>();
241 Sym->InVersionScript = false;
242 Sym->Visibility = STV_DEFAULT;
243 Sym->IsUsedInRegularObj = false;
244 Sym->ExportDynamic = false;
245 Sym->CanInline = true;
246 Sym->Traced = Traced;
247 Sym->VersionId = Config->DefaultSymbolVersion;
248 SymVector.push_back(Sym);
250 Sym = SymVector[SymIndex];
255 // Find an existing symbol or create and insert a new one, then apply the given
257 std::pair<Symbol *, bool> SymbolTable::insert(StringRef Name, uint8_t Type,
259 bool CanOmitFromDynSym,
263 std::tie(S, WasInserted) = insert(Name);
265 // Merge in the new symbol's visibility.
266 S->Visibility = getMinVisibility(S->Visibility, Visibility);
268 if (!CanOmitFromDynSym && (Config->Shared || Config->ExportDynamic))
269 S->ExportDynamic = true;
271 if (!File || File->kind() == InputFile::ObjKind)
272 S->IsUsedInRegularObj = true;
274 if (!WasInserted && S->Type != Symbol::UnknownType &&
275 ((Type == STT_TLS) != S->isTls())) {
276 error("TLS attribute mismatch: " + toString(*S) + "\n>>> defined in " +
277 toString(S->File) + "\n>>> defined in " + toString(File));
280 return {S, WasInserted};
283 template <class ELFT> Symbol *SymbolTable::addUndefined(StringRef Name) {
284 return addUndefined<ELFT>(Name, STB_GLOBAL, STV_DEFAULT,
286 /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
289 static uint8_t getVisibility(uint8_t StOther) { return StOther & 3; }
291 template <class ELFT>
292 Symbol *SymbolTable::addUndefined(StringRef Name, uint8_t Binding,
293 uint8_t StOther, uint8_t Type,
294 bool CanOmitFromDynSym, InputFile *File) {
297 uint8_t Visibility = getVisibility(StOther);
298 std::tie(S, WasInserted) =
299 insert(Name, Type, Visibility, CanOmitFromDynSym, File);
300 // An undefined symbol with non default visibility must be satisfied
302 if (WasInserted || (isa<SharedSymbol>(S) && Visibility != STV_DEFAULT)) {
303 replaceSymbol<Undefined>(S, File, Name, Binding, StOther, Type);
306 if (S->isShared() || S->isLazy() || (S->isUndefined() && Binding != STB_WEAK))
307 S->Binding = Binding;
308 if (Binding != STB_WEAK) {
309 if (auto *SS = dyn_cast<SharedSymbol>(S))
310 if (!Config->GcSections)
311 SS->getFile<ELFT>().IsNeeded = true;
313 if (auto *L = dyn_cast<Lazy>(S)) {
314 // An undefined weak will not fetch archive members. See comment on Lazy in
315 // Symbols.h for the details.
316 if (Binding == STB_WEAK)
318 else if (InputFile *F = L->fetch())
324 // Using .symver foo,foo@@VER unfortunately creates two symbols: foo and
325 // foo@@VER. We want to effectively ignore foo, so give precedence to
327 // FIXME: If users can transition to using
328 // .symver foo,foo@@@VER
329 // we can delete this hack.
330 static int compareVersion(Symbol *S, StringRef Name) {
331 bool A = Name.contains("@@");
332 bool B = S->getName().contains("@@");
340 // We have a new defined symbol with the specified binding. Return 1 if the new
341 // symbol should win, -1 if the new symbol should lose, or 0 if both symbols are
342 // strong defined symbols.
343 static int compareDefined(Symbol *S, bool WasInserted, uint8_t Binding,
349 if (int R = compareVersion(S, Name))
351 if (Binding == STB_WEAK)
358 // We have a new non-common defined symbol with the specified binding. Return 1
359 // if the new symbol should win, -1 if the new symbol should lose, or 0 if there
360 // is a conflict. If the new symbol wins, also update the binding.
361 static int compareDefinedNonCommon(Symbol *S, bool WasInserted, uint8_t Binding,
362 bool IsAbsolute, uint64_t Value,
364 if (int Cmp = compareDefined(S, WasInserted, Binding, Name))
366 if (auto *R = dyn_cast<Defined>(S)) {
367 if (R->Section && isa<BssSection>(R->Section)) {
368 // Non-common symbols take precedence over common symbols.
369 if (Config->WarnCommon)
370 warn("common " + S->getName() + " is overridden");
373 if (R->Section == nullptr && Binding == STB_GLOBAL && IsAbsolute &&
380 Symbol *SymbolTable::addCommon(StringRef N, uint64_t Size, uint32_t Alignment,
381 uint8_t Binding, uint8_t StOther, uint8_t Type,
385 std::tie(S, WasInserted) = insert(N, Type, getVisibility(StOther),
386 /*CanOmitFromDynSym*/ false, &File);
387 int Cmp = compareDefined(S, WasInserted, Binding, N);
389 auto *Bss = make<BssSection>("COMMON", Size, Alignment);
391 Bss->Live = !Config->GcSections;
392 InputSections.push_back(Bss);
394 replaceSymbol<Defined>(S, &File, N, Binding, StOther, Type, 0, Size, Bss);
395 } else if (Cmp == 0) {
396 auto *D = cast<Defined>(S);
397 auto *Bss = dyn_cast_or_null<BssSection>(D->Section);
399 // Non-common symbols take precedence over common symbols.
400 if (Config->WarnCommon)
401 warn("common " + S->getName() + " is overridden");
405 if (Config->WarnCommon)
406 warn("multiple common of " + D->getName());
408 Bss->Alignment = std::max(Bss->Alignment, Alignment);
409 if (Size > Bss->Size) {
410 D->File = Bss->File = &File;
411 D->Size = Bss->Size = Size;
417 static void warnOrError(const Twine &Msg) {
418 if (Config->AllowMultipleDefinition)
424 static void reportDuplicate(Symbol *Sym, InputFile *NewFile) {
425 warnOrError("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " +
426 toString(Sym->File) + "\n>>> defined in " + toString(NewFile));
429 static void reportDuplicate(Symbol *Sym, InputSectionBase *ErrSec,
430 uint64_t ErrOffset) {
431 Defined *D = cast<Defined>(Sym);
432 if (!D->Section || !ErrSec) {
433 reportDuplicate(Sym, ErrSec ? ErrSec->File : nullptr);
437 // Construct and print an error message in the form of:
439 // ld.lld: error: duplicate symbol: foo
440 // >>> defined at bar.c:30
441 // >>> bar.o (/home/alice/src/bar.o)
442 // >>> defined at baz.c:563
443 // >>> baz.o in archive libbaz.a
444 auto *Sec1 = cast<InputSectionBase>(D->Section);
445 std::string Src1 = Sec1->getSrcMsg(*Sym, D->Value);
446 std::string Obj1 = Sec1->getObjMsg(D->Value);
447 std::string Src2 = ErrSec->getSrcMsg(*Sym, ErrOffset);
448 std::string Obj2 = ErrSec->getObjMsg(ErrOffset);
450 std::string Msg = "duplicate symbol: " + toString(*Sym) + "\n>>> defined at ";
452 Msg += Src1 + "\n>>> ";
453 Msg += Obj1 + "\n>>> defined at ";
455 Msg += Src2 + "\n>>> ";
460 Symbol *SymbolTable::addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
461 uint64_t Value, uint64_t Size, uint8_t Binding,
462 SectionBase *Section, InputFile *File) {
465 std::tie(S, WasInserted) = insert(Name, Type, getVisibility(StOther),
466 /*CanOmitFromDynSym*/ false, File);
467 int Cmp = compareDefinedNonCommon(S, WasInserted, Binding, Section == nullptr,
470 replaceSymbol<Defined>(S, File, Name, Binding, StOther, Type, Value, Size,
473 reportDuplicate(S, dyn_cast_or_null<InputSectionBase>(Section), Value);
477 template <typename ELFT>
478 void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> &File,
479 const typename ELFT::Sym &Sym, uint32_t Alignment,
480 uint32_t VerdefIndex) {
481 // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
482 // as the visibility, which will leave the visibility in the symbol table
486 std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
487 /*CanOmitFromDynSym*/ true, &File);
488 // Make sure we preempt DSO symbols with default visibility.
489 if (Sym.getVisibility() == STV_DEFAULT)
490 S->ExportDynamic = true;
492 // An undefined symbol with non default visibility must be satisfied
494 if (WasInserted || ((S->isUndefined() || S->isLazy()) &&
495 S->getVisibility() == STV_DEFAULT)) {
496 uint8_t Binding = S->Binding;
497 bool WasUndefined = S->isUndefined();
498 replaceSymbol<SharedSymbol>(S, File, Name, Sym.getBinding(), Sym.st_other,
499 Sym.getType(), Sym.st_value, Sym.st_size,
500 Alignment, VerdefIndex);
502 S->Binding = Binding;
503 if (!S->isWeak() && !Config->GcSections && WasUndefined)
504 File.IsNeeded = true;
509 Symbol *SymbolTable::addBitcode(StringRef Name, uint8_t Binding,
510 uint8_t StOther, uint8_t Type,
511 bool CanOmitFromDynSym, BitcodeFile &F) {
514 std::tie(S, WasInserted) =
515 insert(Name, Type, getVisibility(StOther), CanOmitFromDynSym, &F);
516 int Cmp = compareDefinedNonCommon(S, WasInserted, Binding,
517 /*IsAbs*/ false, /*Value*/ 0, Name);
519 replaceSymbol<Defined>(S, &F, Name, Binding, StOther, Type, 0, 0, nullptr);
521 reportDuplicate(S, &F);
525 Symbol *SymbolTable::find(StringRef Name) {
526 auto It = SymMap.find(CachedHashStringRef(Name));
527 if (It == SymMap.end())
529 if (It->second == -1)
531 return SymVector[It->second];
534 template <class ELFT>
535 Symbol *SymbolTable::addLazyArchive(StringRef Name, ArchiveFile &F,
536 const object::Archive::Symbol Sym) {
539 std::tie(S, WasInserted) = insert(Name);
541 replaceSymbol<LazyArchive>(S, F, Sym, Symbol::UnknownType);
544 if (!S->isUndefined())
547 // An undefined weak will not fetch archive members. See comment on Lazy in
548 // Symbols.h for the details.
550 replaceSymbol<LazyArchive>(S, F, Sym, S->Type);
551 S->Binding = STB_WEAK;
554 std::pair<MemoryBufferRef, uint64_t> MBInfo = F.getMember(&Sym);
555 if (!MBInfo.first.getBuffer().empty())
556 addFile<ELFT>(createObjectFile(MBInfo.first, F.getName(), MBInfo.second));
560 template <class ELFT>
561 void SymbolTable::addLazyObject(StringRef Name, LazyObjFile &Obj) {
564 std::tie(S, WasInserted) = insert(Name);
566 replaceSymbol<LazyObject>(S, Obj, Name, Symbol::UnknownType);
569 if (!S->isUndefined())
572 // See comment for addLazyArchive above.
574 replaceSymbol<LazyObject>(S, Obj, Name, S->Type);
575 else if (InputFile *F = Obj.fetch())
579 // If we already saw this symbol, force loading its file.
580 template <class ELFT> void SymbolTable::fetchIfLazy(StringRef Name) {
581 if (Symbol *B = find(Name)) {
582 // Mark the symbol not to be eliminated by LTO
583 // even if it is a bitcode symbol.
584 B->IsUsedInRegularObj = true;
585 if (auto *L = dyn_cast<Lazy>(B))
586 if (InputFile *File = L->fetch())
591 // This function takes care of the case in which shared libraries depend on
592 // the user program (not the other way, which is usual). Shared libraries
593 // may have undefined symbols, expecting that the user program provides
594 // the definitions for them. An example is BSD's __progname symbol.
595 // We need to put such symbols to the main program's .dynsym so that
596 // shared libraries can find them.
597 // Except this, we ignore undefined symbols in DSOs.
598 template <class ELFT> void SymbolTable::scanShlibUndefined() {
599 for (InputFile *F : SharedFiles) {
600 for (StringRef U : cast<SharedFile<ELFT>>(F)->getUndefinedSymbols()) {
601 Symbol *Sym = find(U);
602 if (!Sym || !Sym->isDefined())
604 Sym->ExportDynamic = true;
606 // If -dynamic-list is given, the default version is set to
607 // VER_NDX_LOCAL, which prevents a symbol to be exported via .dynsym.
608 // Set to VER_NDX_GLOBAL so the symbol will be handled as if it were
609 // specified by -dynamic-list.
610 Sym->VersionId = VER_NDX_GLOBAL;
615 // Initialize DemangledSyms with a map from demangled symbols to symbol
616 // objects. Used to handle "extern C++" directive in version scripts.
618 // The map will contain all demangled symbols. That can be very large,
619 // and in LLD we generally want to avoid do anything for each symbol.
620 // Then, why are we doing this? Here's why.
622 // Users can use "extern C++ {}" directive to match against demangled
623 // C++ symbols. For example, you can write a pattern such as
624 // "llvm::*::foo(int, ?)". Obviously, there's no way to handle this
625 // other than trying to match a pattern against all demangled symbols.
626 // So, if "extern C++" feature is used, we need to demangle all known
628 StringMap<std::vector<Symbol *>> &SymbolTable::getDemangledSyms() {
629 if (!DemangledSyms) {
630 DemangledSyms.emplace();
631 for (Symbol *Sym : SymVector) {
632 if (!Sym->isDefined())
634 if (Optional<std::string> S = demangleItanium(Sym->getName()))
635 (*DemangledSyms)[*S].push_back(Sym);
637 (*DemangledSyms)[Sym->getName()].push_back(Sym);
640 return *DemangledSyms;
643 std::vector<Symbol *> SymbolTable::findByVersion(SymbolVersion Ver) {
645 return getDemangledSyms().lookup(Ver.Name);
646 if (Symbol *B = find(Ver.Name))
652 std::vector<Symbol *> SymbolTable::findAllByVersion(SymbolVersion Ver) {
653 std::vector<Symbol *> Res;
654 StringMatcher M(Ver.Name);
656 if (Ver.IsExternCpp) {
657 for (auto &P : getDemangledSyms())
658 if (M.match(P.first()))
659 Res.insert(Res.end(), P.second.begin(), P.second.end());
663 for (Symbol *Sym : SymVector)
664 if (Sym->isDefined() && M.match(Sym->getName()))
669 // If there's only one anonymous version definition in a version
670 // script file, the script does not actually define any symbol version,
671 // but just specifies symbols visibilities.
672 void SymbolTable::handleAnonymousVersion() {
673 for (SymbolVersion &Ver : Config->VersionScriptGlobals)
674 assignExactVersion(Ver, VER_NDX_GLOBAL, "global");
675 for (SymbolVersion &Ver : Config->VersionScriptGlobals)
676 assignWildcardVersion(Ver, VER_NDX_GLOBAL);
677 for (SymbolVersion &Ver : Config->VersionScriptLocals)
678 assignExactVersion(Ver, VER_NDX_LOCAL, "local");
679 for (SymbolVersion &Ver : Config->VersionScriptLocals)
680 assignWildcardVersion(Ver, VER_NDX_LOCAL);
683 // Handles -dynamic-list.
684 void SymbolTable::handleDynamicList() {
685 for (SymbolVersion &Ver : Config->DynamicList) {
686 std::vector<Symbol *> Syms;
688 Syms = findAllByVersion(Ver);
690 Syms = findByVersion(Ver);
692 for (Symbol *B : Syms) {
694 B->ExportDynamic = true;
695 else if (B->includeInDynsym())
696 B->IsPreemptible = true;
701 // Set symbol versions to symbols. This function handles patterns
702 // containing no wildcard characters.
703 void SymbolTable::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
704 StringRef VersionName) {
708 // Get a list of symbols which we need to assign the version to.
709 std::vector<Symbol *> Syms = findByVersion(Ver);
711 if (Config->NoUndefinedVersion)
712 error("version script assignment of '" + VersionName + "' to symbol '" +
713 Ver.Name + "' failed: symbol not defined");
717 // Assign the version.
718 for (Symbol *Sym : Syms) {
719 // Skip symbols containing version info because symbol versions
720 // specified by symbol names take precedence over version scripts.
721 // See parseSymbolVersion().
722 if (Sym->getName().contains('@'))
725 if (Sym->InVersionScript)
726 warn("duplicate symbol '" + Ver.Name + "' in version script");
727 Sym->VersionId = VersionId;
728 Sym->InVersionScript = true;
732 void SymbolTable::assignWildcardVersion(SymbolVersion Ver, uint16_t VersionId) {
733 if (!Ver.HasWildcard)
736 // Exact matching takes precendence over fuzzy matching,
737 // so we set a version to a symbol only if no version has been assigned
738 // to the symbol. This behavior is compatible with GNU.
739 for (Symbol *B : findAllByVersion(Ver))
740 if (B->VersionId == Config->DefaultSymbolVersion)
741 B->VersionId = VersionId;
744 // This function processes version scripts by updating VersionId
745 // member of symbols.
746 void SymbolTable::scanVersionScript() {
747 // Handle edge cases first.
748 handleAnonymousVersion();
751 // Now we have version definitions, so we need to set version ids to symbols.
752 // Each version definition has a glob pattern, and all symbols that match
753 // with the pattern get that version.
755 // First, we assign versions to exact matching symbols,
756 // i.e. version definitions not containing any glob meta-characters.
757 for (VersionDefinition &V : Config->VersionDefinitions)
758 for (SymbolVersion &Ver : V.Globals)
759 assignExactVersion(Ver, V.Id, V.Name);
761 // Next, we assign versions to fuzzy matching symbols,
762 // i.e. version definitions containing glob meta-characters.
763 // Note that because the last match takes precedence over previous matches,
764 // we iterate over the definitions in the reverse order.
765 for (VersionDefinition &V : llvm::reverse(Config->VersionDefinitions))
766 for (SymbolVersion &Ver : V.Globals)
767 assignWildcardVersion(Ver, V.Id);
769 // Symbol themselves might know their versions because symbols
770 // can contain versions in the form of <name>@<version>.
771 // Let them parse and update their names to exclude version suffix.
772 for (Symbol *Sym : SymVector)
773 Sym->parseSymbolVersion();
776 template void SymbolTable::addSymbolWrap<ELF32LE>(StringRef);
777 template void SymbolTable::addSymbolWrap<ELF32BE>(StringRef);
778 template void SymbolTable::addSymbolWrap<ELF64LE>(StringRef);
779 template void SymbolTable::addSymbolWrap<ELF64BE>(StringRef);
781 template Symbol *SymbolTable::addUndefined<ELF32LE>(StringRef);
782 template Symbol *SymbolTable::addUndefined<ELF32BE>(StringRef);
783 template Symbol *SymbolTable::addUndefined<ELF64LE>(StringRef);
784 template Symbol *SymbolTable::addUndefined<ELF64BE>(StringRef);
786 template Symbol *SymbolTable::addUndefined<ELF32LE>(StringRef, uint8_t, uint8_t,
787 uint8_t, bool, InputFile *);
788 template Symbol *SymbolTable::addUndefined<ELF32BE>(StringRef, uint8_t, uint8_t,
789 uint8_t, bool, InputFile *);
790 template Symbol *SymbolTable::addUndefined<ELF64LE>(StringRef, uint8_t, uint8_t,
791 uint8_t, bool, InputFile *);
792 template Symbol *SymbolTable::addUndefined<ELF64BE>(StringRef, uint8_t, uint8_t,
793 uint8_t, bool, InputFile *);
795 template void SymbolTable::addCombinedLTOObject<ELF32LE>();
796 template void SymbolTable::addCombinedLTOObject<ELF32BE>();
797 template void SymbolTable::addCombinedLTOObject<ELF64LE>();
798 template void SymbolTable::addCombinedLTOObject<ELF64BE>();
801 SymbolTable::addLazyArchive<ELF32LE>(StringRef, ArchiveFile &,
802 const object::Archive::Symbol);
804 SymbolTable::addLazyArchive<ELF32BE>(StringRef, ArchiveFile &,
805 const object::Archive::Symbol);
807 SymbolTable::addLazyArchive<ELF64LE>(StringRef, ArchiveFile &,
808 const object::Archive::Symbol);
810 SymbolTable::addLazyArchive<ELF64BE>(StringRef, ArchiveFile &,
811 const object::Archive::Symbol);
813 template void SymbolTable::addLazyObject<ELF32LE>(StringRef, LazyObjFile &);
814 template void SymbolTable::addLazyObject<ELF32BE>(StringRef, LazyObjFile &);
815 template void SymbolTable::addLazyObject<ELF64LE>(StringRef, LazyObjFile &);
816 template void SymbolTable::addLazyObject<ELF64BE>(StringRef, LazyObjFile &);
818 template void SymbolTable::addShared<ELF32LE>(StringRef, SharedFile<ELF32LE> &,
819 const typename ELF32LE::Sym &,
820 uint32_t Alignment, uint32_t);
821 template void SymbolTable::addShared<ELF32BE>(StringRef, SharedFile<ELF32BE> &,
822 const typename ELF32BE::Sym &,
823 uint32_t Alignment, uint32_t);
824 template void SymbolTable::addShared<ELF64LE>(StringRef, SharedFile<ELF64LE> &,
825 const typename ELF64LE::Sym &,
826 uint32_t Alignment, uint32_t);
827 template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> &,
828 const typename ELF64BE::Sym &,
829 uint32_t Alignment, uint32_t);
831 template void SymbolTable::fetchIfLazy<ELF32LE>(StringRef);
832 template void SymbolTable::fetchIfLazy<ELF32BE>(StringRef);
833 template void SymbolTable::fetchIfLazy<ELF64LE>(StringRef);
834 template void SymbolTable::fetchIfLazy<ELF64BE>(StringRef);
836 template void SymbolTable::scanShlibUndefined<ELF32LE>();
837 template void SymbolTable::scanShlibUndefined<ELF32BE>();
838 template void SymbolTable::scanShlibUndefined<ELF64LE>();
839 template void SymbolTable::scanShlibUndefined<ELF64BE>();