[lld] r285796 - [ELF] - Check that .dynsym is present in DSO if SHT_GNU_versym section is.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 2 03:16:25 PDT 2016


Author: grimar
Date: Wed Nov  2 05:16:25 2016
New Revision: 285796

URL: http://llvm.org/viewvc/llvm-project?rev=285796&view=rev
Log:
[ELF] - Check that .dynsym is present in DSO if SHT_GNU_versym section is.

When we have SHT_GNU_versym section, it is should be associated with symbol table
section. Usually (and in out implementation) it is .dynsym.
In case when .dynsym is absent (due to broken object for example), 
lld crashes in parseVerdefs() when accesses null pointer:

Versym = reinterpret_cast<const Elf_Versym *>(this->ELFObj.base() +
                                              VersymSec->sh_offset) +
         this->Symtab->sh_info;

DIfferential revision: https://reviews.llvm.org/D25553

Added:
    lld/trunk/test/ELF/invalid/verdef-no-symtab.test
Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/SymbolTable.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=285796&r1=285795&r2=285796&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Nov  2 05:16:25 2016
@@ -610,6 +610,9 @@ template <class ELFT> void SharedFile<EL
     }
   }
 
+  if (this->VersymSec && !this->Symtab)
+    error("SHT_GNU_versym should be associated with symbol table");
+
   this->initStringTable();
 
   // DSOs are identified by soname, and they usually contain

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=285796&r1=285795&r2=285796&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Nov  2 05:16:25 2016
@@ -77,7 +77,7 @@ template <class ELFT> void SymbolTable<E
   if (auto *F = dyn_cast<SharedFile<ELFT>>(File)) {
     // DSOs are uniquified not by filename but by soname.
     F->parseSoName();
-    if (!SoNames.insert(F->getSoName()).second)
+    if (HasError || !SoNames.insert(F->getSoName()).second)
       return;
     SharedFiles.push_back(F);
     F->parseRest();

Added: lld/trunk/test/ELF/invalid/verdef-no-symtab.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/verdef-no-symtab.test?rev=285796&view=auto
==============================================================================
--- lld/trunk/test/ELF/invalid/verdef-no-symtab.test (added)
+++ lld/trunk/test/ELF/invalid/verdef-no-symtab.test Wed Nov  2 05:16:25 2016
@@ -0,0 +1,26 @@
+# RUN: yaml2obj %s -o %t
+# RUN: not ld.lld %t -o %tout 2>&1 | FileCheck %s
+
+## When we have SHT_GNU_versym section, it is should be associated
+## with symbol table section.
+--- !ELF
+FileHeader:
+  Class:           ELFCLASS64
+  Data:            ELFDATA2LSB
+  Type:            ET_DYN
+  Machine:         EM_X86_64
+Sections:
+  - Name:            .versym
+    Type:            SHT_GNU_versym
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x1
+    Content:         "00000000"
+
+  - Name:            .verdef
+    Type:            SHT_GNU_verdef
+    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
+    AddressAlign:    0x1
+    Content:         "00000000"
+
+
+# CHECK: SHT_GNU_versym should be associated with symbol table




More information about the llvm-commits mailing list