[llvm] [llvm-link] Improve missing file error message (PR #82514)

Michael Halkenhäuser via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 10:04:12 PST 2024


https://github.com/mhalk created https://github.com/llvm/llvm-project/pull/82514

Add error messages showing the missing filenames.

Currently, we only get 'No such file or directory' without any(!) further info. This patch will (only upon ENOENT error) iterate over all requested files and print which ones are actually missing.

>From 0314d0f58480442dbe69738fdd29bbbde361cba7 Mon Sep 17 00:00:00 2001
From: Michael Halkenhaeuser <mhalkenh at amd.com>
Date: Wed, 21 Feb 2024 11:58:17 -0600
Subject: [PATCH] [llvm-link] Improve missing file error message

Add error messages showing the missing filenames.

Currently, we only get 'No such file or directory' without any(!) further info.
This patch will (only upon ENOENT error) iterate over all requested files and
print which ones are actually missing.
---
 llvm/tools/llvm-link/llvm-link.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/llvm/tools/llvm-link/llvm-link.cpp b/llvm/tools/llvm-link/llvm-link.cpp
index e6c219a8cd7ece..e653ae31364744 100644
--- a/llvm/tools/llvm-link/llvm-link.cpp
+++ b/llvm/tools/llvm-link/llvm-link.cpp
@@ -393,8 +393,17 @@ static bool linkFiles(const char *argv0, LLVMContext &Context, Linker &L,
   // Similar to some flags, internalization doesn't apply to the first file.
   bool InternalizeLinkedSymbols = false;
   for (const auto &File : Files) {
+    auto ErrOrExpected = MemoryBuffer::getFileOrSTDIN(File);
+
+    // When we encounter a missing file, print all missing files to stderr.
+    if (auto EC = ErrOrExpected.getError())
+      if (EC == std::errc::no_such_file_or_directory)
+        for (auto &F : Files)
+          if (!llvm::sys::fs::exists(F))
+            errs() << "No such file or directory: '" << F << "'\n";
+
     std::unique_ptr<MemoryBuffer> Buffer =
-        ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(File)));
+        ExitOnErr(errorOrToExpected(std::move(ErrOrExpected)));
 
     std::unique_ptr<Module> M =
         identify_magic(Buffer->getBuffer()) == file_magic::archive



More information about the llvm-commits mailing list