From: Sam Clegg Date: Tue, 1 Mar 2022 00:32:02 +0000 (-0800) Subject: [lld][WebAssembly] Improve error reporting for bad ar archive members X-Git-Tag: upstream/15.0.7~14911 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1cf6ebc0e9031a433eb8c40652c9904a53f537f7;p=platform%2Fupstream%2Fllvm.git [lld][WebAssembly] Improve error reporting for bad ar archive members Show the name of of the archive in the error message as well as the name of the object within it. Differential Revision: https://reviews.llvm.org/D120689 --- diff --git a/lld/test/wasm/bad-archive-member.s b/lld/test/wasm/bad-archive-member.s new file mode 100644 index 0000000..029027a --- /dev/null +++ b/lld/test/wasm/bad-archive-member.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 + +# RUN: rm -rf %t.dir +# RUN: mkdir -p %t.dir +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux -o %t.dir/elf.o %s +# RUN: llvm-ar rcs %t.dir/libfoo.a %t.dir/elf.o +# RUN: not wasm-ld %t.dir/libfoo.a -o /dev/null 2>&1 | FileCheck %s +# CHECK: error: unknown file type: {{.*}}libfoo.a(elf.o) + +.globl _start +_start: diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 1e69f16..ebff723 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -87,7 +87,12 @@ InputFile *createObjectFile(MemoryBufferRef mb, StringRef archiveName, if (magic == file_magic::bitcode) return make(mb, archiveName, offsetInArchive); - fatal("unknown file type: " + mb.getBufferIdentifier()); + std::string name = mb.getBufferIdentifier().str(); + if (!archiveName.empty()) { + name = archiveName.str() + "(" + name + ")"; + } + + fatal("unknown file type: " + name); } // Relocations contain either symbol or type indices. This function takes a