[lld] 54a366f - [ELF] Add a corrector for case mismatch problems

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 26 09:16:18 PST 2019


Author: Fangrui Song
Date: 2019-11-26T09:11:56-08:00
New Revision: 54a366f5156edc34019d5f04fff6844848d87f99

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

LOG: [ELF] Add a corrector for case mismatch problems

Reviewed By: grimar, peter.smith

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

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp
    lld/test/ELF/undef-spell-corrector.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 80e1de24316f..1b8dacb36627 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -777,6 +777,14 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
       return s;
   }
 
+  // Case mismatch, e.g. Foo vs FOO.
+  for (auto &it : map)
+    if (name.equals_lower(it.first))
+      return it.second;
+  for (Symbol *sym : symtab->symbols())
+    if (!sym->isUndefined() && name.equals_lower(sym->getName()))
+      return sym;
+
   // The reference may be a mangled name while the definition is not. Suggest a
   // missing extern "C".
   if (name.startswith("_Z")) {

diff  --git a/lld/test/ELF/undef-spell-corrector.s b/lld/test/ELF/undef-spell-corrector.s
index 174c8009cba8..3ad2421a6cd6 100644
--- a/lld/test/ELF/undef-spell-corrector.s
+++ b/lld/test/ELF/undef-spell-corrector.s
@@ -63,6 +63,16 @@
 # CONST-NEXT: >>> referenced by {{.*}}
 # CONST-NEXT: >>> did you mean: foo(int const*)
 
+## Case mismatch.
+# RUN: echo 'call _Z3FOOPKi' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
+# RUN: not ld.lld %t.o %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=CASE %s
+# RUN: echo '_Z3fooPKi: call _Z3FOOPKi' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o
+# RUN: not ld.lld %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=CASE %s
+
+# CASE:      error: undefined symbol: FOO(int const*)
+# CASE-NEXT: >>> referenced by {{.*}}
+# CASE-NEXT: >>> did you mean: foo(int const*)
+
 .globl _start, abcde, _Z3fooPKi
 _start:
 abcde:


        


More information about the llvm-commits mailing list