[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 08:43:58 PDT 2019
ruiu created this revision.
ruiu added a reviewer: efriedma.
Herald added subscribers: MaskRay, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Include an archive file name in an error message for a bad file.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D59212
Files:
lld/ELF/InputFiles.cpp
lld/test/ELF/invalid/invalid-elf.test
Index: lld/test/ELF/invalid/invalid-elf.test
===================================================================
--- lld/test/ELF/invalid/invalid-elf.test
+++ lld/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): 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): invalid file class
# RUN: not ld.lld %p/Inputs/binding.elf -o %t2 2>&1 | \
# RUN: FileCheck --check-prefix=INVALID-BINDING %s
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -1188,20 +1188,27 @@
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) {
+ if (ArchiveName.empty())
+ fatal(MB.getBufferIdentifier() + ": " + Msg);
+ else
+ fatal(ArchiveName + "(" + MB.getBufferIdentifier() + "): " + 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 +1243,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 +1258,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 +1300,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.190097.patch
Type: text/x-patch
Size: 2951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190311/5343e6fe/attachment.bin>
More information about the llvm-commits
mailing list