diff options
| author | Eugene Leviant <eleviant@accesssoftek.com> | 2016-11-21 09:28:07 +0000 |
|---|---|---|
| committer | Eugene Leviant <eleviant@accesssoftek.com> | 2016-11-21 09:28:07 +0000 |
| commit | 7d7ff80f4b374e325fd988b925982c6a4ca9169a (patch) | |
| tree | b8efff5b06e2fb85817d9335f2f068b6b20c132e | |
| parent | a113a4194c00b9867e2a1091fbd460b625e0d8bf (diff) | |
| download | bcm5719-llvm-7d7ff80f4b374e325fd988b925982c6a4ca9169a.tar.gz bcm5719-llvm-7d7ff80f4b374e325fd988b925982c6a4ca9169a.zip | |
[ELF] Better error reporting for broken archives
Differential revision: https://reviews.llvm.org/D26852
llvm-svn: 287527
| -rw-r--r-- | lld/ELF/Driver.cpp | 15 | ||||
| -rw-r--r-- | lld/ELF/InputFiles.cpp | 3 | ||||
| -rw-r--r-- | lld/test/ELF/bad-archive.s | 13 |
3 files changed, 24 insertions, 7 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index b337feada09..4cff5dcb4d1 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -99,21 +99,24 @@ static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef Emul) { 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()) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 406fedabbf9..72d8148dedf 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -482,7 +482,8 @@ SymbolBody *elf::ObjectFile<ELFT>::createSymbolBody(const Elf_Sym *Sym) { } 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()) diff --git a/lld/test/ELF/bad-archive.s b/lld/test/ELF/bad-archive.s new file mode 100644 index 00000000000..ed9567b2b23 --- /dev/null +++ b/lld/test/ELF/bad-archive.s @@ -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: |

