[lld] r287527 - [ELF] Better error reporting for broken archives

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 21 01:28:08 PST 2016


Author: evgeny777
Date: Mon Nov 21 03:28:07 2016
New Revision: 287527

URL: http://llvm.org/viewvc/llvm-project?rev=287527&view=rev
Log:
[ELF] Better error reporting for broken archives

Differential revision: https://reviews.llvm.org/D26852

Added:
    lld/trunk/test/ELF/bad-archive.s
Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/InputFiles.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=287527&r1=287526&r2=287527&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Mon Nov 21 03:28:07 2016
@@ -99,21 +99,24 @@ static std::tuple<ELFKind, uint16_t, uin
 std::vector<MemoryBufferRef>
 LinkerDriver::getArchiveMembers(MemoryBufferRef MB) {
   std::unique_ptr<Archive> File =
-      check(Archive::create(MB), "failed to parse archive");
+      check(Archive::create(MB),
+            MB.getBufferIdentifier() + ": failed to parse archive");
 
   std::vector<MemoryBufferRef> V;
   Error Err = Error::success();
   for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) {
-    Archive::Child C = check(COrErr, "could not get the child of the archive " +
-                                         File->getFileName());
+    Archive::Child C =
+        check(COrErr, MB.getBufferIdentifier() +
+                          ": could not get the child of the archive");
     MemoryBufferRef MBRef =
         check(C.getMemoryBufferRef(),
-              "could not get the buffer for a child of the archive " +
-                  File->getFileName());
+              MB.getBufferIdentifier() +
+                  ": could not get the buffer for a child of the archive");
     V.push_back(MBRef);
   }
   if (Err)
-    fatal("Archive::children failed: " + toString(std::move(Err)));
+    fatal(MB.getBufferIdentifier() + ": Archive::children failed: " +
+          toString(std::move(Err)));
 
   // Take ownership of memory buffers created for members of thin archives.
   for (std::unique_ptr<MemoryBuffer> &MB : File->takeThinBuffers())

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=287527&r1=287526&r2=287527&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Nov 21 03:28:07 2016
@@ -482,7 +482,8 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
 }
 
 template <class ELFT> void ArchiveFile::parse() {
-  File = check(Archive::create(MB), "failed to parse archive");
+  File = check(Archive::create(MB),
+               MB.getBufferIdentifier() + ": failed to parse archive");
 
   // Read the symbol table to construct Lazy objects.
   for (const Archive::Symbol &Sym : File->symbols())

Added: lld/trunk/test/ELF/bad-archive.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/bad-archive.s?rev=287527&view=auto
==============================================================================
--- lld/trunk/test/ELF/bad-archive.s (added)
+++ lld/trunk/test/ELF/bad-archive.s Mon Nov 21 03:28:07 2016
@@ -0,0 +1,13 @@
+// REQUIRES: x86
+
+// Check bad archive error reporting with --whole-archive
+// and without it.
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+// RUN: echo "!<arch>" > %t.bad.a
+// RUN: echo "bad archive" >> %t.bad.a
+// RUN: not ld.lld %t.o %t.bad.a -o %t 2>&1 | FileCheck %s
+// RUN: not ld.lld %t.o --whole-archive %t.bad.a -o %t 2>&1 | FileCheck %s
+// CHECK: {{.*}}.bad.a: failed to parse archive
+
+.globl _start
+_start:




More information about the llvm-commits mailing list