diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 43b39bcb1fde..abf97f4fceb7 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -283,7 +283,7 @@ static int compareDefined(Symbol *S, bool WasInserted, uint8_t Binding) { if (WasInserted) return 1; SymbolBody *Body = S->body(); - if (Body->isLazy() || Body->isUndefined() || Body->isShared()) + if (Body->isLazy() || !Body->isInCurrentDSO()) return 1; if (Binding == STB_WEAK) return -1; @@ -464,9 +464,9 @@ template SymbolBody *SymbolTable::find(StringRef Name) { } template -SymbolBody *SymbolTable::findDefined(StringRef Name) { +SymbolBody *SymbolTable::findInCurrentDSO(StringRef Name) { if (SymbolBody *S = find(Name)) - if (S->isDefined() && !S->isShared()) + if (S->isInCurrentDSO()) return S; return nullptr; } diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h index bfed1a79829f..f39dbd1e2e18 100644 --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -82,7 +82,7 @@ public: void scanVersionScript(); SymbolBody *find(StringRef Name); - SymbolBody *findDefined(StringRef Name); + SymbolBody *findInCurrentDSO(StringRef Name); void trace(StringRef Name); void wrap(StringRef Name); diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 7c2b5fb959cc..0fe42be250cf 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -203,8 +203,8 @@ void SymbolBody::parseSymbolVersion() { // Truncate the symbol name so that it doesn't include the version string. Name = {S.data(), Pos}; - // If this is an undefined or shared symbol it is not a definition. - if (isUndefined() || isShared()) + // If this is not in this DSO, it is not a definition. + if (!isInCurrentDSO()) return; // '@@' in a symbol name means the default version. @@ -300,7 +300,7 @@ uint8_t Symbol::computeBinding() const { if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) return STB_LOCAL; const SymbolBody *Body = body(); - if (VersionId == VER_NDX_LOCAL && !Body->isUndefined() && !Body->isShared()) + if (VersionId == VER_NDX_LOCAL && Body->isInCurrentDSO()) return STB_LOCAL; if (Config->NoGnuUnique && Binding == STB_GNU_UNIQUE) return STB_GLOBAL; diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index af85dc2b121d..7acb89ad0718 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -67,6 +67,7 @@ public: return SymbolKind == LazyArchiveKind || SymbolKind == LazyObjectKind; } bool isShared() const { return SymbolKind == SharedKind; } + bool isInCurrentDSO() const { return !isUndefined() && !isShared(); } bool isLocal() const { return IsLocal; } bool isPreemptible() const; StringRef getName() const { return Name; } diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 920a7c830269..e66c461e7e86 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -883,9 +883,9 @@ template void DynamicSection::finalize() { add({DT_FINI_ARRAYSZ, Out::FiniArray, Entry::SecSize}); } - if (SymbolBody *B = Symtab::X->findDefined(Config->Init)) + if (SymbolBody *B = Symtab::X->findInCurrentDSO(Config->Init)) add({DT_INIT, B}); - if (SymbolBody *B = Symtab::X->findDefined(Config->Fini)) + if (SymbolBody *B = Symtab::X->findInCurrentDSO(Config->Fini)) add({DT_FINI, B}); bool HasVerNeed = In::VerNeed->getNeedNum() != 0; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index fc41e7284c95..d93468fef34f 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -664,7 +664,7 @@ static void addOptionalSynthetic(StringRef Name, OutputSectionBase *Sec, typename ELFT::uint Val, uint8_t StOther = STV_HIDDEN) { if (SymbolBody *S = Symtab::X->find(Name)) - if (S->isUndefined() || S->isShared()) + if (!S->isInCurrentDSO()) Symtab::X->addSynthetic(Name, Sec, Val, StOther); } @@ -684,7 +684,7 @@ static Symbol *addOptionalRegular(StringRef Name, InputSectionBase *IS, SymbolBody *S = Symtab::X->find(Name); if (!S) return nullptr; - if (!S->isUndefined() && !S->isShared()) + if (S->isInCurrentDSO()) return S->symbol(); return addRegular(Name, IS, Value); }