[ELF] Print symbols with non-default versions for better "undefined symbol" diagnostics
authorFangrui Song <maskray@google.com>
Sat, 28 Mar 2020 22:48:38 +0000 (15:48 -0700)
committerFangrui Song <maskray@google.com>
Wed, 1 Apr 2020 15:04:36 +0000 (08:04 -0700)
commitf2036a15d3714fc9cfc8935634814d1c4e4263fa
tree5803856fa2104b4c70dec2210e3d57b0544519ec
parentf527e6f2e11dcda8e71c21138fa15e3a3b9e9917
[ELF] Print symbols with non-default versions for better "undefined symbol" diagnostics

When reporting an "undefined symbol" diagnostic:

* We don't print @ for the reference.
* We don't print @ or @@ for the definition. https://bugs.llvm.org/show_bug.cgi?id=45318

This can lead to confusing diagnostics:

```
// foo may be foo@v2
ld.lld: error: undefined symbol: foo
>>> referenced by t1.o:(.text+0x1)
// foo may be foo@v1 or foo@@v1
>>> did you mean: foo
>>> defined in: t.so
```

There are 2 ways a symbol in symtab may get truncated:

* A @@ definition may be truncated *early* by SymbolTable::insert().
  The name ends with a '\0'.
* A @ definition/reference may be truncated *later* by Symbol::parseSymbolVersion().
  The name ends with a '@'.

This patch detects the second case and improves the diagnostics. The first case is
not improved but the second case is sufficient to make diagnostics not confusing.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D76999
lld/ELF/Symbols.cpp
lld/ELF/Symbols.h
lld/test/ELF/undef-suggest-version.s [new file with mode: 0644]