Index: lld/COFF/DriverUtils.cpp =================================================================== --- lld/COFF/DriverUtils.cpp +++ lld/COFF/DriverUtils.cpp @@ -746,7 +746,7 @@ if (!RF) fatal("cannot compile non-resource file as resource"); if (auto EC = Parser.parse(RF)) - fatal("failed to parse .res file: " + toString(std::move(EC))); + fatal(toString(std::move(EC))); } Expected> E = Index: llvm/include/llvm/Object/WindowsResource.h =================================================================== --- llvm/include/llvm/Object/WindowsResource.h +++ llvm/include/llvm/Object/WindowsResource.h @@ -120,6 +120,7 @@ const WindowsResource *Owner); BinaryStreamReader Reader; + const WindowsResource *Owner; bool IsStringType; ArrayRef Type; uint16_t TypeID; Index: llvm/lib/Object/WindowsResource.cpp =================================================================== --- llvm/lib/Object/WindowsResource.cpp +++ llvm/lib/Object/WindowsResource.cpp @@ -46,11 +46,12 @@ 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 @@ 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 @@ 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));