Skip to content

Commit f9c8ebd

Browse files
committed
[ELF] Don't suggest alternative spelling of an empty name
Fix PR50111 Differential Revision: https://reviews.llvm.org/D101698
1 parent 039bdcc commit f9c8ebd

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lld/ELF/Relocations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
763763

764764
// Build a map of local defined symbols.
765765
for (const Symbol *s : sym.file->getSymbols())
766-
if (s->isLocal() && s->isDefined())
766+
if (s->isLocal() && s->isDefined() && !s->getName().empty())
767767
map.try_emplace(s->getName(), s);
768768
}
769769

lld/test/ELF/undef-not-suggest.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,31 @@ Symbols:
5252
Section: .text.foo
5353
- Name: for
5454
Section: .data
55+
56+
## Check we don't suggest an empty name symbol (e.g. STT_SECTION).
57+
58+
# RUN: yaml2obj --docnum=2 %s -o %t2.o
59+
# RUN: not ld.lld %t2.o -o /dev/null 2>&1 | FileCheck %s
60+
61+
--- !ELF
62+
FileHeader:
63+
Class: ELFCLASS64
64+
Data: ELFDATA2LSB
65+
Type: ET_REL
66+
Machine: EM_X86_64
67+
Sections:
68+
- Name: .text
69+
Type: SHT_PROGBITS
70+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
71+
- Name: .rela.text
72+
Type: SHT_RELA
73+
Info: .text
74+
Relocations:
75+
- Type: R_X86_64_64
76+
Symbol: f
77+
Symbols:
78+
- Name: ""
79+
Type: STT_SECTION
80+
Section: .text
81+
- Name: f
82+
Binding: STB_GLOBAL

0 commit comments

Comments
 (0)