[lld] 3eb4bf1 - [ELF] Append " [--no-allow-shlib-undefined]" to the corresponding diagnostics
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 08:00:20 PDT 2020
Author: Fangrui Song
Date: 2020-06-03T07:59:37-07:00
New Revision: 3eb4bf13bae85fb48c4eca8c59c84491015fb4d6
URL: https://github.com/llvm/llvm-project/commit/3eb4bf13bae85fb48c4eca8c59c84491015fb4d6
DIFF: https://github.com/llvm/llvm-project/commit/3eb4bf13bae85fb48c4eca8c59c84491015fb4d6.diff
LOG: [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
Added:
Modified:
lld/ELF/Writer.cpp
lld/test/ELF/allow-shlib-undefined.s
lld/test/ELF/wrap-shlib-undefined.s
Removed:
################################################################################
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 9a6be7931a28..9f64e4f34e12 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -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-
diff --git a/lld/test/ELF/allow-shlib-undefined.s b/lld/test/ELF/allow-shlib-undefined.s
index 5b09681f2e9d..59205552eb3c 100644
--- a/lld/test/ELF/allow-shlib-undefined.s
+++ b/lld/test/ELF/allow-shlib-undefined.s
@@ -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 at PLT
-# CHECK: undefined reference to _unresolved
+# CHECK: {{.*}}.so: undefined reference to _unresolved [--no-allow-shlib-undefined]
diff --git a/lld/test/ELF/wrap-shlib-undefined.s b/lld/test/ELF/wrap-shlib-undefined.s
index c9c4abeb35fa..8bbda963f070 100644
--- a/lld/test/ELF/wrap-shlib-undefined.s
+++ b/lld/test/ELF/wrap-shlib-undefined.s
@@ -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
More information about the llvm-commits
mailing list