[lld] Improve readability of "undefined reference" message (PR #82671)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 22 11:32:12 PST 2024


https://github.com/DeanSturtevant1 updated https://github.com/llvm/llvm-project/pull/82671

>From 023cf559b06a111b9683129fe3f5d112a0dbea70 Mon Sep 17 00:00:00 2001
From: DeanSturtevant1 <48059325+DeanSturtevant1 at users.noreply.github.com>
Date: Thu, 22 Feb 2024 13:21:25 -0500
Subject: [PATCH 1/3] Improve readability of "undefined reference" message

The current message implies a command line flag caused an undefined reference. This of course is wrong and causes confusion. The message now more accurately reflects the true state of affairs.
---
 lld/ELF/Writer.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0bbf43ddf694aa..cf8825296213b2 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2057,8 +2057,9 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
           if (sym->dsoDefined)
             continue;
           if (sym->isUndefined() && !sym->isWeak()) {
-            diagnose("undefined reference due to --no-allow-shlib-undefined: " +
-                     toString(*sym) + "\n>>> referenced by " + toString(file));
+            diagnose("undefined reference: " +
+                     toString(*sym) + "\n>>> referenced by " + toString(file) +
+                     " (disallowed by --no-allow-shlib-undefined)");
           } else if (sym->isDefined() && sym->computeBinding() == STB_LOCAL) {
             diagnose("non-exported symbol '" + toString(*sym) + "' in '" +
                      toString(sym->file) + "' is referenced by DSO '" +

>From 5a1a451c8dd93aa9c9775e4d742fabc05b27f030 Mon Sep 17 00:00:00 2001
From: DeanSturtevant1 <dsturtevant at google.com>
Date: Thu, 22 Feb 2024 13:33:27 -0500
Subject: [PATCH 2/3] Applied clang-format changes.

---
 lld/ELF/Writer.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index cf8825296213b2..a9292b3b1a2241 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2057,8 +2057,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
           if (sym->dsoDefined)
             continue;
           if (sym->isUndefined() && !sym->isWeak()) {
-            diagnose("undefined reference: " +
-                     toString(*sym) + "\n>>> referenced by " + toString(file) +
+            diagnose("undefined reference: " + toString(*sym) +
+                     "\n>>> referenced by " + toString(file) +
                      " (disallowed by --no-allow-shlib-undefined)");
           } else if (sym->isDefined() && sym->computeBinding() == STB_LOCAL) {
             diagnose("non-exported symbol '" + toString(*sym) + "' in '" +

>From fe471334a2582e2dc98d1128075409500875a108 Mon Sep 17 00:00:00 2001
From: DeanSturtevant1 <dsturtevant at google.com>
Date: Thu, 22 Feb 2024 14:32:05 -0500
Subject: [PATCH 3/3] Update allow-shlib-undefined.s

---
 lld/test/ELF/allow-shlib-undefined.s | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lld/test/ELF/allow-shlib-undefined.s b/lld/test/ELF/allow-shlib-undefined.s
index 969e87b69eb856..5d7045d385f442 100644
--- a/lld/test/ELF/allow-shlib-undefined.s
+++ b/lld/test/ELF/allow-shlib-undefined.s
@@ -43,7 +43,7 @@
 # RUN: ld.lld --gc-sections main.o a.so def.so def-hidden.o --fatal-warnings -o /dev/null
 
 # CHECK-NOT:   error:
-# CHECK:       error: undefined reference due to --no-allow-shlib-undefined: x1{{$}}
+# CHECK:       error: undefined reference: x1{{$}}
 # CHECK-NEXT:  >>> referenced by a.so{{$}}
 # CHECK-NOT:   {{.}}
 



More information about the llvm-commits mailing list