[PATCH] D70506: [ELF] Add a corrector for case mismatch problems

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 12:51:04 PST 2019


MaskRay created this revision.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay updated this revision to Diff 230317.
MaskRay added reviewers: grimar, peter.smith, ruiu.
MaskRay added a comment.
MaskRay edited the summary of this revision.

.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70506

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


Index: lld/test/ELF/undef-spell-corrector.s
===================================================================
--- lld/test/ELF/undef-spell-corrector.s
+++ 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:
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -777,6 +777,14 @@
       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)
+    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")) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70506.230317.patch
Type: text/x-patch
Size: 1434 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191120/35716fdb/attachment-0001.bin>


More information about the llvm-commits mailing list