[PATCH] D38712: [ELF] Try to not emit weird diagnostics on undefined symbols

Davide Italiano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 9 19:29:34 PDT 2017


davide created this revision.
Herald added a subscriber: emaste.

Fixes https://bugs.llvm.org/show_bug.cgi?id=34872


https://reviews.llvm.org/D38712

Files:
  ELF/Relocations.cpp
  test/ELF/Inputs/undefined-error.s
  test/ELF/pr34872.s


Index: test/ELF/pr34872.s
===================================================================
--- /dev/null
+++ test/ELF/pr34872.s
@@ -0,0 +1,13 @@
+# RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t.o
+# RUN: llvm-mc %p/Inputs/undefined-error.s -filetype=obj \
+# RUN:    -triple=x86_64-pc-linux -o %t2.o
+# RUN: ld.lld -shared %t2.o -o %t2.so
+# RUN: not ld.lld %t2.so %t.o 2>&1 | FileCheck %s
+
+# CHECK: undefined symbol: fmod
+# CHECK-NOT: 'fmod' defined in {{.*}} has no type
+
+.global main
+
+main:
+  callq fmod
Index: test/ELF/Inputs/undefined-error.s
===================================================================
--- /dev/null
+++ test/ELF/Inputs/undefined-error.s
@@ -0,0 +1 @@
+callq fmod at PLT
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -859,9 +859,14 @@
     // symbols here means that we report undefined symbols only when
     // they have relocations pointing to them. We don't care about
     // undefined symbols that are in dead-stripped sections.
-    if (!Body.isLocal() && Body.isUndefined() && !Body.symbol()->isWeak())
+    if (!Body.isLocal() && Body.isUndefined() && !Body.symbol()->isWeak()) {
       reportUndefined<ELFT>(Body, Sec, Rel.r_offset);
 
+      // If we report an undefined, and we have an error, go on.
+      if (ErrorCount)
+        continue;
+    }
+
     RelExpr Expr = Target->getRelExpr(Type, Body, *Sec.File,
                                       Sec.Data.begin() + Rel.r_offset);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38712.118305.patch
Type: text/x-patch
Size: 1552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171010/eabbaca7/attachment.bin>


More information about the llvm-commits mailing list