Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -718,15 +718,30 @@ B->symbol()->VersionId = VersionId; } +static bool isDefaultVersion(SymbolBody *B) { + return B->isInCurrentDSO() && B->getName().find("@@") != StringRef::npos; +} + // This function processes version scripts by updating VersionId // member of symbols. template void SymbolTable::scanVersionScript() { // Symbol themselves might know their versions because symbols // can contain versions in the form of @. - // Let them parse their names. - if (!Config->VersionDefinitions.empty()) - for (Symbol *Sym : SymVector) - Sym->body()->parseSymbolVersion(); + // Let them parse and update their names to exclude version suffix. + for (Symbol *Sym : SymVector) { + SymbolBody *Body = Sym->body(); + bool IsDefault = isDefaultVersion(Body); + Body->parseSymbolVersion(); + + // @@ means the symbol is the default version. If that's the + // case, the symbol is not used only to resolve of version + // but also unversioned symbols with name . + if (IsDefault && find(Body->getName())) { + auto *D = cast(Body); + addRegular(D->getName(), D->StOther, D->Type, D->Value, D->Size, + D->symbol()->Binding, D->Section, D->File); + } + } // Handle edge cases first. handleAnonymousVersion(); Index: test/ELF/version-script-symver-err.s =================================================================== --- test/ELF/version-script-symver-err.s +++ test/ELF/version-script-symver-err.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "VERSION { global: *; };" > %t.map +# RUN: not ld.lld %t.o -o %t --version-script %t.map 2>&1 | FileCheck %s +# CHECK: error: duplicate symbol: bar +# CHECK-NEXT: >>> defined at {{.*}}.o +# CHECK-NEXT: >>> defined at {{.*}}.o + +.global _start +.global bar +.symver _start, bar@@VERSION +_start: + jmp bar + +bar: Index: test/ELF/version-script-symver.s =================================================================== --- test/ELF/version-script-symver.s +++ test/ELF/version-script-symver.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "VERSION { global: *; };" > %t.map +# RUN: ld.lld %t.o --version-script %t.map -o %t + +.global _start +.global bar +.symver _start, bar@@VERSION +_start: + jmp bar