[PATCH] D59212: Include an archive file name in an error message for a bad file.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 11 17:27:09 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rLLD355886: Include an archive file name in an error message for a corrupted file. (authored by ruiu, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D59212?vs=190144&id=190190#toc
Repository:
rLLD LLVM Linker
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59212/new/
https://reviews.llvm.org/D59212
Files:
ELF/InputFiles.cpp
test/ELF/invalid/invalid-elf.test
Index: test/ELF/invalid/invalid-elf.test
===================================================================
--- test/ELF/invalid/invalid-elf.test
+++ test/ELF/invalid/invalid-elf.test
@@ -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
Index: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ ELF/InputFiles.cpp
@@ -1188,20 +1188,28 @@
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 @@
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::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 @@
return;
}
- if (getELFKind(this->MB) != Config->EKind) {
+ if (getELFKind(this->MB, ArchiveName) != Config->EKind) {
error("incompatible file: " + this->MB.getBufferIdentifier());
return;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59212.190190.patch
Type: text/x-patch
Size: 3027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190312/65c05fa3/attachment.bin>
More information about the llvm-commits
mailing list