[ELF][Driver] Produce a proper error when file is not found

When a file is not found, produce a proper error message. The previous error
message produced a file format error, which made me wonder for a while why
there is a file format error, but essentially the file was not found.

This fixes the problem by producing a proper error message.

llvm-svn: 217359
This commit is contained in:
Shankar Easwaran 2014-09-08 04:18:11 +00:00
parent 595e056dce
commit c7701e9a8c
2 changed files with 7 additions and 0 deletions

View File

@ -488,6 +488,10 @@ bool GnuLdDriver::parse(int argc, const char *argv[],
// FIXME: Calling getFileMagic() is expensive. It would be better to
// wire up the LdScript parser into the registry.
llvm::sys::fs::file_magic magic = llvm::sys::fs::file_magic::unknown;
if (!llvm::sys::fs::exists(resolvedInputPath)) {
diagnostics << "lld: cannot find file " << userPath << "\n";
return false;
}
std::error_code ec = getFileMagic(*ctx, resolvedInputPath, magic);
if (ec) {
diagnostics << "lld: unknown input file format for file " << userPath

View File

@ -0,0 +1,3 @@
# Check that a file that cannot be found results in a proper error message
RUN: not lld -flavor gnu -target x86_64 %p/Inputs/nofile.o 2>&1 | FileCheck %s
#CHECK: lld: cannot find file {{[-_A-Za-z0-9.\\/:]+}}nofile.o