[lld] r273396 - [ELF] - Do not allow to mix global symbols versions.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 02:10:38 PDT 2016


Author: grimar
Date: Wed Jun 22 04:10:38 2016
New Revision: 273396

URL: http://llvm.org/viewvc/llvm-project?rev=273396&view=rev
Log:
[ELF] - Do not allow to mix global symbols versions.

For next version script:
VER1{
  global:
  a;
};

VER2{
  global:
  a;
};
gold would produce warning like:
"warning: using 'VER1' as version for 'a' which is also named in version 'VER2' in script."

Documentation also says we do not want this duplications (https://people.freebsd.org/~deischen/symver/library_versioning.txt):
"Note that you do not want to duplicate symbols in the map file. The .symver directives are all that is required to add compatibility
symbols into old versions."

This patch restricts such mixing and makes lld to produce error in this case.

Differential revision: http://reviews.llvm.org/D21555

Modified:
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/test/ELF/version-script.s

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=273396&r1=273395&r2=273396&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Jun 22 04:10:38 2016
@@ -531,8 +531,12 @@ template <class ELFT> void SymbolTable<E
   size_t I = 2;
   for (Version &V : Config->SymbolVersions) {
     for (StringRef Name : V.Globals)
-      if (SymbolBody *B = find(Name))
+      if (SymbolBody *B = find(Name)) {
+        if (B->symbol()->VersionId != VER_NDX_GLOBAL &&
+            B->symbol()->VersionId != VER_NDX_LOCAL)
+          error("duplicate symbol " + Name + " in version script");
         B->symbol()->VersionId = I;
+      }
     ++I;
   }
 }

Modified: lld/trunk/test/ELF/version-script.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/version-script.s?rev=273396&r1=273395&r2=273396&view=diff
==============================================================================
--- lld/trunk/test/ELF/version-script.s (original)
+++ lld/trunk/test/ELF/version-script.s Wed Jun 22 04:10:38 2016
@@ -47,6 +47,16 @@
 # RUN: not ld.lld --version-script %t5.script -shared %t.o %t2.so -o %t5.so 2>&1 | \
 # RUN:   FileCheck -check-prefix=ERR %s
 
+# RUN: echo "VERSION_1.0{     \
+# RUN:          global: foo1; \
+# RUN:          local: *; };  \
+# RUN:       VERSION_2.0 {    \
+# RUN:          global: foo1; \
+# RUN:          local: *; }; " > %t6.script
+# RUN: not ld.lld --version-script %t6.script -shared %t.o %t2.so -o %t6.so 2>&1 | \
+# RUN:   FileCheck -check-prefix=ERR2 %s
+# ERR2: duplicate symbol foo1 in version script
+
 # RUN: ld.lld --version-script %t.script --dynamic-list %t.list %t.o %t2.so -o %t2
 # RUN: llvm-readobj %t2 > /dev/null
 




More information about the llvm-commits mailing list