[lld] [Support] Better error msg when cache dir can't be created. (PR #69575)
Tobias Hieta via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 25 05:29:41 PDT 2023
https://github.com/tru updated https://github.com/llvm/llvm-project/pull/69575
>From 4a8f4029abfcc876137d1fb9c9d0f59f47a0c828 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias.hieta at ubisoft.com>
Date: Thu, 19 Oct 2023 11:10:35 +0200
Subject: [PATCH 1/9] [Support] Better error msg when cache dir can't be
created.
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.
---
llvm/lib/Support/Caching.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index f20f08a865c76ff..722746e7b440390 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -145,7 +145,7 @@ 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);
// Write to a temporary to avoid race condition
SmallString<64> TempFilenameModel;
>From c63d11b39559126cbe378c115057f496d25ff107 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias.hieta at ubisoft.com>
Date: Thu, 19 Oct 2023 11:34:38 +0200
Subject: [PATCH 2/9] Fix formatting
---
llvm/lib/Support/Caching.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 722746e7b440390..c13957ba849387d 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -145,7 +145,8 @@ 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 createStringError(EC, Twine("Can't create cache directory: ") + CacheDirectoryPath);
+ return createStringError(EC, Twine("Can't create cache directory: ") +
+ CacheDirectoryPath);
// Write to a temporary to avoid race condition
SmallString<64> TempFilenameModel;
>From d7d4b00c1d18c6de3c80d4fdebbbddb8153541d3 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias.hieta at ubisoft.com>
Date: Fri, 20 Oct 2023 09:49:05 +0200
Subject: [PATCH 3/9] Add test (wip)
---
lld/test/COFF/lto-cache-errors.ll | 18 ++++++++++++++++++
llvm/lib/Support/Caching.cpp | 4 ++--
2 files changed, 20 insertions(+), 2 deletions(-)
create mode 100644 lld/test/COFF/lto-cache-errors.ll
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
new file mode 100644
index 000000000000000..4314a3dd2512cea
--- /dev/null
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -0,0 +1,18 @@
+; REQUIRES: x86
+
+; 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, note that this test will pass if there is a o: drive.
+; RUN: not lld-link /lldltocache:%t.cache/cache /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
+; CHECK: LLVM ERROR: Can't create cache directory
+
+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 c13957ba849387d..4e6de2d42ca6c73 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -145,8 +145,8 @@ 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 createStringError(EC, Twine("Can't create cache directory: ") +
- CacheDirectoryPath);
+ return createStringError(EC, Twine("Can't create cache directory ") +
+ CacheDirectoryPath + ": " + EC.message());
// Write to a temporary to avoid race condition
SmallString<64> TempFilenameModel;
>From 799f0bc049f8d404ba8d1d52bafeb03fcc88c720 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias at hieta.se>
Date: Mon, 23 Oct 2023 12:35:48 +0200
Subject: [PATCH 4/9] Fix test on crash
---
lld/test/COFF/lto-cache-errors.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index 4314a3dd2512cea..49ef7fbd6e958a4 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -6,7 +6,7 @@
; RUN: chmod 444 %t.cache
;; Check emit warnings when we can't create the cache dir, note that this test will pass if there is a o: drive.
-; RUN: not lld-link /lldltocache:%t.cache/cache /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
+; RUN: not --crash lld-link /lldltocache:%t.cache/cache /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
; CHECK: LLVM ERROR: Can't create cache directory
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
>From 700988fd809fbb2ead9cf1a3ad0dae66a1d688a0 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias at hieta.se>
Date: Mon, 23 Oct 2023 12:36:06 +0200
Subject: [PATCH 5/9] Formatting
---
llvm/lib/Support/Caching.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 4e6de2d42ca6c73..97a070ef4d5363d 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -146,7 +146,8 @@ Expected<FileCache> llvm::localCache(const Twine &CacheNameRef,
if (std::error_code EC = sys::fs::create_directories(
CacheDirectoryPath, /*IgnoreExisting=*/true))
return createStringError(EC, Twine("Can't create cache directory ") +
- CacheDirectoryPath + ": " + EC.message());
+ CacheDirectoryPath + ": " +
+ EC.message());
// Write to a temporary to avoid race condition
SmallString<64> TempFilenameModel;
>From 6c1203490d7c409162534df78ff59f5bb3dfb696 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias at hieta.se>
Date: Mon, 23 Oct 2023 12:40:35 +0200
Subject: [PATCH 6/9] More fixes
---
lld/test/COFF/lto-cache-errors.ll | 2 ++
llvm/lib/Support/Caching.cpp | 2 +-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index 49ef7fbd6e958a4..56ba28a9d423116 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -1,4 +1,6 @@
; 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
diff --git a/llvm/lib/Support/Caching.cpp b/llvm/lib/Support/Caching.cpp
index 97a070ef4d5363d..628e23e1cb3d191 100644
--- a/llvm/lib/Support/Caching.cpp
+++ b/llvm/lib/Support/Caching.cpp
@@ -145,7 +145,7 @@ 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 createStringError(EC, Twine("Can't create cache directory ") +
+ return createStringError(EC, Twine("can't create cache directory ") +
CacheDirectoryPath + ": " +
EC.message());
>From 3353feea1342f40f24b339bc85a472289d18cf02 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias at hieta.se>
Date: Mon, 23 Oct 2023 15:29:36 +0200
Subject: [PATCH 7/9] Fix test case casing
---
lld/test/COFF/lto-cache-errors.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index 56ba28a9d423116..48c158fc0699151 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -9,7 +9,7 @@
;; Check emit warnings when we can't create the cache dir, note that this test will pass if there is a o: drive.
; RUN: not --crash lld-link /lldltocache:%t.cache/cache /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
-; CHECK: LLVM ERROR: Can't create cache directory
+; CHECK: LLVM ERROR: can't create cache directory
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"
>From b6aa73c3f9fb7e6f2001d5bbcb260d7ef8e89600 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias at hieta.se>
Date: Mon, 23 Oct 2023 15:31:07 +0200
Subject: [PATCH 8/9] Fix test case comment
---
lld/test/COFF/lto-cache-errors.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index 48c158fc0699151..c24f1d88eff4ef9 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -7,7 +7,7 @@
; RUN: rm -Rf %t.cache && mkdir %t.cache
; RUN: chmod 444 %t.cache
-;; Check emit warnings when we can't create the cache dir, note that this test will pass if there is a o: drive.
+;; Check emit warnings when we can't create the cache dir
; RUN: not --crash lld-link /lldltocache:%t.cache/cache /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
; CHECK: LLVM ERROR: can't create cache directory
>From ec99549dfaa0febbea602723e2bc2d50c9956b46 Mon Sep 17 00:00:00 2001
From: Tobias Hieta <tobias at hieta.se>
Date: Wed, 25 Oct 2023 14:29:07 +0200
Subject: [PATCH 9/9] Check specific error as suggested by aeubanks
---
lld/test/COFF/lto-cache-errors.ll | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lld/test/COFF/lto-cache-errors.ll b/lld/test/COFF/lto-cache-errors.ll
index c24f1d88eff4ef9..55244e5690dc34a 100644
--- a/lld/test/COFF/lto-cache-errors.ll
+++ b/lld/test/COFF/lto-cache-errors.ll
@@ -8,8 +8,8 @@
; RUN: chmod 444 %t.cache
;; Check emit warnings when we can't create the cache dir
-; RUN: not --crash lld-link /lldltocache:%t.cache/cache /out:%t3 /entry:main %t2.o %t.o 2>&1 | FileCheck %s
-; CHECK: LLVM ERROR: can't create cache directory
+; 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"
More information about the llvm-commits
mailing list