Skip to content

Commit 3eb4bf1

Browse files
committed
[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
1 parent d20fdca commit 3eb4bf1

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

lld/ELF/Writer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
19801980
if (sym->isUndefined() && !sym->isWeak())
19811981
if (auto *f = dyn_cast_or_null<SharedFile>(sym->file))
19821982
if (f->allNeededIsKnown)
1983-
error(toString(f) + ": undefined reference to " + toString(*sym));
1983+
errorOrWarn(toString(f) + ": undefined reference to " +
1984+
toString(*sym) + " [--no-allow-shlib-undefined]");
19841985
}
19851986

19861987
// Now that we have defined all possible global symbols including linker-

lld/test/ELF/allow-shlib-undefined.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# RUN: not ld.lld --no-allow-shlib-undefined %t.o %t.so -o /dev/null 2>&1 | FileCheck %s
1010
# Executable defaults to --no-allow-shlib-undefined
1111
# RUN: not ld.lld %t.o %t.so -o /dev/null 2>&1 | FileCheck %s
12+
# RUN: ld.lld %t.o %t.so --noinhibit-exec -o /dev/null 2>&1 | FileCheck %s
1213
# -shared defaults to --allow-shlib-undefined
1314
# RUN: ld.lld -shared %t.o %t.so -o /dev/null
1415

@@ -27,4 +28,4 @@
2728
_start:
2829
callq _shared@PLT
2930

30-
# CHECK: undefined reference to _unresolved
31+
# CHECK: {{.*}}.so: undefined reference to _unresolved [--no-allow-shlib-undefined]

lld/test/ELF/wrap-shlib-undefined.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## --no-allow-shlib-undefined errors because __real_foo is not defined.
88
# RUN: not ld.lld %t.o %t.so -o /dev/null 2>&1 | FileCheck --check-prefix=ERR %s
9-
# ERR: undefined reference to __real_foo
9+
# ERR: {{.*}}.so: undefined reference to __real_foo [--no-allow-shlib-undefined]
1010

1111
## --wrap=foo defines __real_foo.
1212
# RUN: ld.lld %t.o %t.so --wrap=foo -o %t

0 commit comments

Comments
 (0)