Bug 26781 - ld: Suggest alternative spelling for "undefined reference" diagnostics
Summary: ld: Suggest alternative spelling for "undefined reference" diagnostics
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-23 22:43 UTC by Fangrui Song
Modified: 2023-08-07 09:48 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2020-10-23 22:43:19 UTC
For an undefined symbol diagnostic, I have implemented the following corrector for LLD, ordered in usefulness from high to low:

(a) There is a defined symbol with Levenshtein distance 1 or a transposition

https://reviews.llvm.org/D67039 This is probably good enough and it can suggest some missing/superfluous qualifiers: const, restrict, volatile, & and && ref-qualifier, e.g.

 error: undefined symbol: foo(int*)
 >>> referenced by b.o:(.text+0x1)
+>>> did you mean: foo(int const*)
+>>> defined in: a.o

 error: undefined symbol: foo(int*&)
 >>> referenced by b.o:(.text+0x1)
+>>> did you mean: foo(int*)
+>>> defined in: b.o

(b) Case mismatch

ld.lld: error: undefined symbol: FOO(int const*)
>>> referenced by {{.*}}
>>> did you mean: foo(int const*)

(UpdateToGet -> UpdateToGET)

(c) Between the undefined symbol and the candidate, one is extern "C" and the other is a raw C symbol.

ld.lld: error: undefined symbol: foo(int)
>>> referenced by {{.*}}
>>> did you mean: extern "C" foo

ld.lld: error: undefined symbol: foo
>>> referenced by {{.*}}
>>> did you mean to declare foo(int) as extern "C"?