From c7701e9a8c1c8c1e92ac6a01387963f1db4f6e77 Mon Sep 17 00:00:00 2001 From: Shankar Easwaran Date: Mon, 8 Sep 2014 04:18:11 +0000 Subject: [PATCH] [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 --- lld/lib/Driver/GnuLdDriver.cpp | 4 ++++ lld/test/elf/filenotfound.test | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 lld/test/elf/filenotfound.test diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index c6dda412921b..683bf318ef53 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -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 diff --git a/lld/test/elf/filenotfound.test b/lld/test/elf/filenotfound.test new file mode 100644 index 000000000000..a5b623faec8d --- /dev/null +++ b/lld/test/elf/filenotfound.test @@ -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