Skip to content

Commit a6d509f

Browse files
authored
[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.
1 parent 926173c commit a6d509f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; REQUIRES: x86
2+
;; Not supported on windows since we use permissions to deny the creation
3+
; UNSUPPORTED: system-windows
4+
5+
; RUN: opt -module-hash -module-summary %s -o %t.o
6+
; RUN: opt -module-hash -module-summary %p/Inputs/lto-cache.ll -o %t2.o
7+
; RUN: rm -Rf %t.cache && mkdir %t.cache
8+
; RUN: chmod 444 %t.cache
9+
10+
;; Check emit warnings when we can't create the cache dir
11+
; RUN: not --crash lld-link /lldltocache:%t.cache/nonexistant/ /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
12+
; CHECK: LLVM ERROR: can't create cache directory {{.*}}/nonexistant/: Permission denied
13+
14+
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
15+
target triple = "x86_64-pc-windows-msvc"
16+
17+
define void @globalfunc() #0 {
18+
entry:
19+
ret void
20+
}

llvm/lib/Support/Caching.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
145145
// ensures the filesystem isn't mutated until the cache is.
146146
if (std::error_code EC = sys::fs::create_directories(
147147
CacheDirectoryPath, /*IgnoreExisting=*/true))
148-
return errorCodeToError(EC);
148+
return createStringError(EC, Twine("can't create cache directory ") +
149+
CacheDirectoryPath + ": " +
150+
EC.message());
149151

150152
// Write to a temporary to avoid race condition
151153
SmallString<64> TempFilenameModel;

0 commit comments

Comments
 (0)