From: Nico Weber Date: Thu, 2 May 2019 01:52:24 +0000 (+0000) Subject: lld-link: Make "duplicate resource" error message a bit more concise X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d49213afe09393c9c2c6e395ddc909191188a513;p=llvm lld-link: Make "duplicate resource" error message a bit more concise Reduces the error message from: lld-link: error: failed to parse .res file: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in test1.res and in test2.res To: lld-link: error: duplicate resource: type STRINGTABLE (ID 6)/name ID 3/language 1033, in test1.res and in test2.res Make sure every error message emitted by cvtres contains the name of at least one ".res" file, so that removing the "failed to parse .res file" string doesn't lose information. Differential Revision: https://reviews.llvm.org/D61388 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359749 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Object/WindowsResource.h b/include/llvm/Object/WindowsResource.h index 553fde2f17b..7cd41cc3653 100644 --- a/include/llvm/Object/WindowsResource.h +++ b/include/llvm/Object/WindowsResource.h @@ -120,6 +120,7 @@ private: const WindowsResource *Owner); BinaryStreamReader Reader; + const WindowsResource *Owner; bool IsStringType; ArrayRef Type; uint16_t TypeID; diff --git a/lib/Object/WindowsResource.cpp b/lib/Object/WindowsResource.cpp index 2ad5e941b9d..e84133575e8 100644 --- a/lib/Object/WindowsResource.cpp +++ b/lib/Object/WindowsResource.cpp @@ -46,11 +46,12 @@ WindowsResource::WindowsResource(MemoryBufferRef Source) support::little); } +// static Expected> WindowsResource::createWindowsResource(MemoryBufferRef Source) { if (Source.getBufferSize() < WIN_RES_MAGIC_SIZE + WIN_RES_NULL_ENTRY_SIZE) return make_error( - "File too small to be a resource file", + Source.getBufferIdentifier() + ": too small to be a resource file", object_error::invalid_file_type); std::unique_ptr Ret(new WindowsResource(Source)); return std::move(Ret); @@ -58,14 +59,14 @@ WindowsResource::createWindowsResource(MemoryBufferRef Source) { Expected WindowsResource::getHeadEntry() { if (BBS.getLength() < sizeof(WinResHeaderPrefix) + sizeof(WinResHeaderSuffix)) - return make_error(".res contains no entries", + return make_error(getFileName() + " contains no entries", object_error::unexpected_eof); return ResourceEntryRef::create(BinaryStreamRef(BBS), this); } ResourceEntryRef::ResourceEntryRef(BinaryStreamRef Ref, const WindowsResource *Owner) - : Reader(Ref) {} + : Reader(Ref), Owner(Owner) {} Expected ResourceEntryRef::create(BinaryStreamRef BSR, const WindowsResource *Owner) { @@ -108,7 +109,8 @@ Error ResourceEntryRef::loadNext() { RETURN_IF_ERROR(Reader.readObject(Prefix)); if (Prefix->HeaderSize < MIN_HEADER_SIZE) - return make_error("Header size is too small.", + return make_error(Owner->getFileName() + + ": header size too small", object_error::parse_failed); RETURN_IF_ERROR(readStringOrId(Reader, TypeID, Type, IsStringType));