[ELF] Append " [--no-allow-shlib-undefined]" to the corresponding diagnostics
authorFangrui Song <maskray@google.com>
Wed, 3 Jun 2020 14:59:28 +0000 (07:59 -0700)
committerFangrui Song <maskray@google.com>
Wed, 3 Jun 2020 14:59:37 +0000 (07:59 -0700)
commit3eb4bf13bae85fb48c4eca8c59c84491015fb4d6
treec9ad407bfc485f38770898cbd100345f9ec1c1cc
parentd20fdcabf82fb30239a3f361950814e39e4c20a8
[ELF] Append " [--no-allow-shlib-undefined]" to the corresponding diagnostics

--no-allow-shlib-undefined (enabled by default when linking an
executable) rejects unresolved references in shared objects.

Users may be confused by the common diagnostics of unresolved symbols in
object files (LLD: "undefined symbol: foo"; GNU ld/gold: "undefined reference to")

Learn from GCC/clang " [-Wfoo]": append the option name to the
diagnostics. Users can find relevant information by searching
"--no-allow-shlib-undefined".  It should also be obvious to them that
the positive form --allow-shlib-undefined can suppress the error.

Also downgrade the error to a warning if --noinhibit-exec is used (compatible
with GNU ld and gold).

Reviewed By: grimar, psmith

Differential Revision: https://reviews.llvm.org/D81028
lld/ELF/Writer.cpp
lld/test/ELF/allow-shlib-undefined.s
lld/test/ELF/wrap-shlib-undefined.s