From dd9dd488fc78dff9e1ba30092f215ae6b7fef7ca Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 9 Dec 2016 22:40:49 +0000 Subject: [PATCH] Fix a bogus warning. We first decide that the symbol is global, than that it should have version foo. Since it was already not the default version, we were producing a bogus warning. llvm-svn: 289284 --- lld/ELF/SymbolTable.cpp | 7 +++++-- lld/ELF/Symbols.h | 3 +++ lld/test/ELF/version-script-no-warn.s | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 lld/test/ELF/version-script-no-warn.s diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp index 863e1c8..8927500 100644 --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -192,6 +192,7 @@ std::pair SymbolTable::insert(StringRef Name) { Symbol *Sym; if (IsNew) { Sym = new (BAlloc) Symbol; + Sym->InVersionScript = false; Sym->Binding = STB_WEAK; Sym->Visibility = STV_DEFAULT; Sym->IsUsedInRegularObj = false; @@ -643,9 +644,11 @@ void SymbolTable::assignExactVersion(SymbolVersion Ver, uint16_t VersionId continue; } - if (B->symbol()->VersionId != Config->DefaultSymbolVersion) + Symbol *Sym = B->symbol(); + if (Sym->InVersionScript) warn("duplicate symbol '" + Ver.Name + "' in version script"); - B->symbol()->VersionId = VersionId; + Sym->VersionId = VersionId; + Sym->InVersionScript = true; } } diff --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h index 4a646bc..5f78d17 100644 --- a/lld/ELF/Symbols.h +++ b/lld/ELF/Symbols.h @@ -405,6 +405,9 @@ struct Symbol { // True if this symbol is specified by --trace-symbol option. unsigned Traced : 1; + // This symbol version was found in a version script. + unsigned InVersionScript : 1; + bool includeInDynsym() const; bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; } diff --git a/lld/test/ELF/version-script-no-warn.s b/lld/test/ELF/version-script-no-warn.s new file mode 100644 index 0000000..6a89715 --- /dev/null +++ b/lld/test/ELF/version-script-no-warn.s @@ -0,0 +1,12 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/shared.s -o %t2.o +# RUN: ld.lld -shared %t2.o -soname shared -o %t2.so + +# RUN: echo "foo { global: bar; local: *; };" > %t.script +# RUN: ld.lld --fatal-warnings --shared --version-script %t.script %t.o %t2.so + +.global bar +bar: + nop -- 2.7.4