diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -763,7 +763,7 @@ // Build a map of local defined symbols. for (const Symbol *s : sym.file->getSymbols()) - if (s->isLocal() && s->isDefined()) + if (s->isLocal() && s->isDefined() && !s->getName().empty()) map.try_emplace(s->getName(), s); } diff --git a/lld/test/ELF/undef-not-suggest.test b/lld/test/ELF/undef-not-suggest.test --- a/lld/test/ELF/undef-not-suggest.test +++ b/lld/test/ELF/undef-not-suggest.test @@ -52,3 +52,31 @@ Section: .text.foo - Name: for Section: .data + +## Check we don't suggest an empty name symbol (e.g. STT_SECTION). + +# RUN: yaml2obj --docnum=2 %s -o %t2.o +# RUN: not ld.lld %t2.o -o /dev/null 2>&1 | FileCheck %s + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + - Name: .rela.text + Type: SHT_RELA + Info: .text + Relocations: + - Type: R_X86_64_64 + Symbol: f +Symbols: + - Name: "" + Type: STT_SECTION + Section: .text + - Name: f + Binding: STB_GLOBAL