[PATCH] D25553: [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
Thu Oct 13 04:51:28 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar, evgeny777.

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;


https://reviews.llvm.org/D25553

Files:
  ELF/InputFiles.cpp
  test/ELF/invalid/Inputs/verdef-no-symtab.elf
  test/ELF/invalid/verdef-no-symtab.s


Index: test/ELF/invalid/verdef-no-symtab.s
===================================================================
--- test/ELF/invalid/verdef-no-symtab.s
+++ test/ELF/invalid/verdef-no-symtab.s
@@ -0,0 +1,7 @@
+# REQUIRES: x86
+
+## Version symbol section (SHT_GNU_versym) should be associated
+## with symbol table. verdef-no-symtab.elf has SHT_GNU_versym section,
+## but does not have .dynsym
+# RUN: not ld.lld %S/Inputs/verdef-no-symtab.elf -o %t 2>&1 | FileCheck %s
+# CHECK: SHT_GNU_versym should be associated with symbol table
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -536,6 +536,9 @@
     }
   }
 
+  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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25553.74495.patch
Type: text/x-patch
Size: 927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161013/48909104/attachment.bin>


More information about the llvm-commits mailing list