[lld] a6d509f - [Support] Better error msg when cache dir can't be created. (#69575)

via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 23:31:37 PDT 2023


Author: Tobias Hieta
Date: 2023-10-26T08:31:33+02:00
New Revision: a6d509fadbf7565baf336c2e25d1798fd40e59c9

URL: https://github.com/llvm/llvm-project/commit/a6d509fadbf7565baf336c2e25d1798fd40e59c9
DIFF: https://github.com/llvm/llvm-project/commit/a6d509fadbf7565baf336c2e25d1798fd40e59c9.diff

LOG: [Support] Better error msg when cache dir can't be created. (#69575)

On windows if you passed /lldltocache:D:\tmp to lld and you didn't have
D: mounted it fail to create the cache dir D:\tmp, but the error message
is pretty hard to understand:

```
c:\code\llvm\llvm-project\out\debug>bin\lld-link.exe /lldltocache:D:\tmp
hello.obj
LLVM ERROR: no such file or directory

PLEASE submit a bug report to
https://github.com/llvm/llvm-project/issues/ and include the crash
backtrace.
Exception Code: 0xC000001D
```

Which lead one of our users to report this as a crash. I have just added
a bit better message so it now says:

```
c:\code\llvm\llvm-project\out\debug>bin\lld-link.exe /lldltocache:D:\tmp
hello.obj
LLVM ERROR: Can't create cache directory: D:\tmp

PLEASE submit a bug report to
https://github.com/llvm/llvm-project/issues/ and include the crash
backtrace.
```

I am not sure this is a fatal error because it's not something that
really should be reported as a bug to LLVM. But at least this gives a
bit more visibility on what to change.

Added: 
    lld/test/COFF/lto-cache-errors.ll

Modified: 
    llvm/lib/Support/Caching.cpp

Removed: 
    


################################################################################
diff  --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
new file mode 100644
index 000000000000000..55244e5690dc34a
--- /dev/null
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -0,0 +1,20 @@
+; REQUIRES: x86
+;; Not supported on windows since we use permissions to deny the creation
+; UNSUPPORTED: system-windows
+
+; RUN: opt -module-hash -module-summary %s -o %t.o
+; RUN: opt -module-hash -module-summary %p/Inputs/lto-cache.ll -o %t2.o
+; RUN: rm -Rf %t.cache && mkdir %t.cache
+; RUN: chmod 444 %t.cache
+
+;; Check emit warnings when we can't create the cache dir
+; RUN: not --crash lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
+; CHECK: LLVM ERROR: can't create cache directory {{.*}}/nonexistant/: Permission denied
+
+target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc"
+
+define void @globalfunc() #0 {
+entry:
+  ret void
+}

diff  --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index f20f08a865c76ff..628e23e1cb3d191 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -145,7 +145,9 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
       // ensures the filesystem isn't mutated until the cache is.
       if (std::error_code EC = sys::fs::create_directories(
               CacheDirectoryPath, /*IgnoreExisting=*/true))
-        return errorCodeToError(EC);
+        return createStringError(EC, Twine("can't create cache directory ") +
+                                         CacheDirectoryPath + ": " +
+                                         EC.message());
 
       // Write to a temporary to avoid race condition
       SmallString<64> TempFilenameModel;


        


More information about the llvm-commits mailing list