diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -759,6 +759,16 @@ return s; } + // The reference may be a mangled name while the definition is unmangled. Try + // suggesting the part before (. + std::string demangled = toString(sym); + auto paren = demangled.find('('); + if (paren != StringRef::npos) { + StringRef newName = demangled.substr(0, paren); + if (const Symbol *s = suggest(newName)) + return s; + } + return nullptr; } diff --git a/lld/test/ELF/undef-spell-corrector.s b/lld/test/ELF/undef-spell-corrector.s --- a/lld/test/ELF/undef-spell-corrector.s +++ b/lld/test/ELF/undef-spell-corrector.s @@ -63,6 +63,14 @@ # CONST-NEXT: >>> referenced by {{.*}} # CONST-NEXT: >>> did you mean: foo(int const*) +## The reference may be mangled while the definition is not. +# RUN: echo 'call _Z5abcdei' | 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=MANGLED %s + +# MANGLED: error: undefined symbol: abcde(int) +# MANGLED-NEXT: >>> referenced by {{.*}} +# MANGLED-NEXT: >>> did you mean: abcde + .globl _start, abcde, _Z3fooPKi _start: abcde: