[lld] r320817 - Handle a VersymIndex of 0 as an error.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 06:52:40 PST 2017


Author: rafael
Date: Fri Dec 15 06:52:40 2017
New Revision: 320817

URL: http://llvm.org/viewvc/llvm-project?rev=320817&view=rev
Log:
Handle a VersymIndex of 0 as an error.

I noticed that the continue this patch deletes was not tested. Trying
to add a test I realized that we never put a VER_NDX_LOCAL symbol in
the dynamic symbol table. There doesn't seem to be any reason for a
linker to use VER_NDX_LOCAL for a defined shared symbol.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/test/ELF/corrupted-version-reference.s

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=320817&r1=320816&r2=320817&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Dec 15 06:52:40 2017
@@ -793,7 +793,7 @@ template <class ELFT> void SharedFile<EL
   // Add symbols to the symbol table.
   Elf_Sym_Range Syms = this->getGlobalELFSyms();
   for (const Elf_Sym &Sym : Syms) {
-    unsigned VersymIndex = 0;
+    unsigned VersymIndex = VER_NDX_GLOBAL;
     if (Versym) {
       VersymIndex = Versym->vs_index;
       ++Versym;
@@ -813,12 +813,9 @@ template <class ELFT> void SharedFile<EL
       continue;
     }
 
-    // Ignore local symbols.
-    if (Versym && VersymIndex == VER_NDX_LOCAL)
-      continue;
     const Elf_Verdef *Ver = nullptr;
     if (VersymIndex != VER_NDX_GLOBAL) {
-      if (VersymIndex >= Verdefs.size()) {
+      if (VersymIndex >= Verdefs.size() || VersymIndex == VER_NDX_LOCAL) {
         error("corrupt input file: version definition index " +
               Twine(VersymIndex) + " for symbol " + Name +
               " is out of bounds\n>>> defined in " + toString(this));

Modified: lld/trunk/test/ELF/corrupted-version-reference.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/corrupted-version-reference.s?rev=320817&r1=320816&r2=320817&view=diff
==============================================================================
--- lld/trunk/test/ELF/corrupted-version-reference.s (original)
+++ lld/trunk/test/ELF/corrupted-version-reference.s Fri Dec 15 06:52:40 2017
@@ -5,6 +5,9 @@
 # CHECK: error: corrupt input file: version definition index 9 for symbol __cxa_finalize is out of bounds
 # CHECK: >>> defined in {{.+}}/corrupt-version-reference.so
 
+# CHECK:      error: corrupt input file: version definition index 0 for symbol _Jv_RegisterClasses is out of bounds
+# CHECK-NEXT: >>> defined in {{.*}}/corrupt-version-reference.so
+
 .globl __start
 __start:
     dla $a0, __cxa_finalize




More information about the llvm-commits mailing list