Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -610,6 +610,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 Index: lld/trunk/ELF/SymbolTable.cpp =================================================================== --- lld/trunk/ELF/SymbolTable.cpp +++ lld/trunk/ELF/SymbolTable.cpp @@ -77,7 +77,7 @@ if (auto *F = dyn_cast>(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(); Index: lld/trunk/test/ELF/invalid/verdef-no-symtab.test =================================================================== --- lld/trunk/test/ELF/invalid/verdef-no-symtab.test +++ lld/trunk/test/ELF/invalid/verdef-no-symtab.test @@ -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