forked from OSchip/llvm-project
[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
This commit is contained in:
parent
d20fdcabf8
commit
3eb4bf13ba
|
@ -1980,7 +1980,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
|
|||
if (sym->isUndefined() && !sym->isWeak())
|
||||
if (auto *f = dyn_cast_or_null<SharedFile>(sym->file))
|
||||
if (f->allNeededIsKnown)
|
||||
error(toString(f) + ": undefined reference to " + toString(*sym));
|
||||
errorOrWarn(toString(f) + ": undefined reference to " +
|
||||
toString(*sym) + " [--no-allow-shlib-undefined]");
|
||||
}
|
||||
|
||||
// Now that we have defined all possible global symbols including linker-
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
# RUN: not ld.lld --no-allow-shlib-undefined %t.o %t.so -o /dev/null 2>&1 | FileCheck %s
|
||||
# Executable defaults to --no-allow-shlib-undefined
|
||||
# RUN: not ld.lld %t.o %t.so -o /dev/null 2>&1 | FileCheck %s
|
||||
# RUN: ld.lld %t.o %t.so --noinhibit-exec -o /dev/null 2>&1 | FileCheck %s
|
||||
# -shared defaults to --allow-shlib-undefined
|
||||
# RUN: ld.lld -shared %t.o %t.so -o /dev/null
|
||||
|
||||
|
@ -27,4 +28,4 @@
|
|||
_start:
|
||||
callq _shared@PLT
|
||||
|
||||
# CHECK: undefined reference to _unresolved
|
||||
# CHECK: {{.*}}.so: undefined reference to _unresolved [--no-allow-shlib-undefined]
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
## --no-allow-shlib-undefined errors because __real_foo is not defined.
|
||||
# RUN: not ld.lld %t.o %t.so -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
|
||||
# ERR: undefined reference to __real_foo
|
||||
# ERR: {{.*}}.so: undefined reference to __real_foo [--no-allow-shlib-undefined]
|
||||
|
||||
## --wrap=foo defines __real_foo.
|
||||
# RUN: ld.lld %t.o %t.so --wrap=foo -o %t
|
||||
|
|
Loading…
Reference in New Issue