[lld] r355886 - Include an archive file name in an error message for a corrupted file.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 11 17:24:34 PDT 2019
Author: ruiu
Date: Mon Mar 11 17:24:34 2019
New Revision: 355886
URL: http://llvm.org/viewvc/llvm-project?rev=355886&view=rev
Log:
Include an archive file name in an error message for a corrupted file.
Differential Revision: https://reviews.llvm.org/D59212
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/test/ELF/invalid/invalid-elf.test
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=355886&r1=355885&r2=355886&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Mon Mar 11 17:24:34 2019
@@ -1188,20 +1188,28 @@ void BitcodeFile::parse(DenseSet<CachedH
Symbols.push_back(createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, *this));
}
-static ELFKind getELFKind(MemoryBufferRef MB) {
+static ELFKind getELFKind(MemoryBufferRef MB, StringRef ArchiveName) {
unsigned char Size;
unsigned char Endian;
std::tie(Size, Endian) = getElfArchType(MB.getBuffer());
+ auto Fatal = [&](StringRef Msg) {
+ StringRef Filename = MB.getBufferIdentifier();
+ if (ArchiveName.empty())
+ fatal(Filename + ": corrupted ELF file: " + Msg);
+ else
+ fatal(ArchiveName + "(" + Filename + "): corrupted ELF file: " + Msg);
+ };
+
if (Endian != ELFDATA2LSB && Endian != ELFDATA2MSB)
- fatal(MB.getBufferIdentifier() + ": invalid data encoding");
+ Fatal("invalid data encoding");
if (Size != ELFCLASS32 && Size != ELFCLASS64)
- fatal(MB.getBufferIdentifier() + ": invalid file class");
+ Fatal("invalid file class");
size_t BufSize = MB.getBuffer().size();
if ((Size == ELFCLASS32 && BufSize < sizeof(Elf32_Ehdr)) ||
(Size == ELFCLASS64 && BufSize < sizeof(Elf64_Ehdr)))
- fatal(MB.getBufferIdentifier() + ": file is too short");
+ Fatal("file is too short");
if (Size == ELFCLASS32)
return (Endian == ELFDATA2LSB) ? ELF32LEKind : ELF32BEKind;
@@ -1236,7 +1244,7 @@ InputFile *elf::createObjectFile(MemoryB
if (isBitcode(MB))
return make<BitcodeFile>(MB, ArchiveName, OffsetInArchive);
- switch (getELFKind(MB)) {
+ switch (getELFKind(MB, ArchiveName)) {
case ELF32LEKind:
return make<ObjFile<ELF32LE>>(MB, ArchiveName);
case ELF32BEKind:
@@ -1251,7 +1259,7 @@ InputFile *elf::createObjectFile(MemoryB
}
InputFile *elf::createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName) {
- switch (getELFKind(MB)) {
+ switch (getELFKind(MB, "")) {
case ELF32LEKind:
return make<SharedFile<ELF32LE>>(MB, DefaultSoName);
case ELF32BEKind:
@@ -1293,7 +1301,7 @@ template <class ELFT> void LazyObjFile::
return;
}
- if (getELFKind(this->MB) != Config->EKind) {
+ if (getELFKind(this->MB, ArchiveName) != Config->EKind) {
error("incompatible file: " + this->MB.getBufferIdentifier());
return;
}
Modified: lld/trunk/test/ELF/invalid/invalid-elf.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid/invalid-elf.test?rev=355886&r1=355885&r2=355886&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid/invalid-elf.test (original)
+++ lld/trunk/test/ELF/invalid/invalid-elf.test Mon Mar 11 17:24:34 2019
@@ -3,11 +3,11 @@
# RUN: not ld.lld %t %p/Inputs/data-encoding.a -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-DATA-ENC %s
-# INVALID-DATA-ENC: test.o: invalid data encoding
+# INVALID-DATA-ENC: data-encoding.a(test.o): corrupted ELF file: invalid data encoding
# RUN: not ld.lld %t %p/Inputs/file-class.a -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-FILE-CLASS %s
-# INVALID-FILE-CLASS: test.o: invalid file class
+# INVALID-FILE-CLASS: file-class.a(test.o): corrupted ELF file: invalid file class
# RUN: not ld.lld %p/Inputs/binding.elf -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-BINDING %s
More information about the llvm-commits
mailing list