Fix a bogus warning.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 9 Dec 2016 22:40:49 +0000 (22:40 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 9 Dec 2016 22:40:49 +0000 (22:40 +0000)
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
lld/ELF/Symbols.h
lld/test/ELF/version-script-no-warn.s [new file with mode: 0644]

index 863e1c8..8927500 100644 (file)
@@ -192,6 +192,7 @@ std::pair<Symbol *, bool> SymbolTable<ELFT>::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<ELFT>::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;
   }
 }
 
index 4a646bc..5f78d17 100644 (file)
@@ -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 (file)
index 0000000..6a89715
--- /dev/null
@@ -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