[lld] f9c8ebd - [ELF] Don't suggest alternative spelling of an empty name

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon May 3 09:05:05 PDT 2021


Author: Fangrui Song
Date: 2021-05-03T09:04:55-07:00
New Revision: f9c8ebdc30c2796a8d2b253d29f9a75f2e0f3cb0

URL: https://github.com/llvm/llvm-project/commit/f9c8ebdc30c2796a8d2b253d29f9a75f2e0f3cb0
DIFF: https://github.com/llvm/llvm-project/commit/f9c8ebdc30c2796a8d2b253d29f9a75f2e0f3cb0.diff

LOG: [ELF] Don't suggest alternative spelling of an empty name

Fix PR50111

Differential Revision: https://reviews.llvm.org/D101698

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp
    lld/test/ELF/undef-not-suggest.test

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index bcb1fe012b659..5302d56f14250 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -763,7 +763,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
 
     // 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
index b4205cae14d5d..b8eebd3148f7e 100644
--- a/lld/test/ELF/undef-not-suggest.test
+++ b/lld/test/ELF/undef-not-suggest.test
@@ -52,3 +52,31 @@ Symbols:
     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


        


More information about the llvm-commits mailing list