Skip to content

Commit b117a3b

Browse files
[ThinLTO] Don't try to replay cache if no hash was computed
There are certain cases where an bitcode arrives in ThinLTOCodeGenerator and it lacks information to compute a cache key for incremental builds. In those cases, don't try to replay the output object file from an non-existing location. rdar://106432595
1 parent f2f9d70 commit b117a3b

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,20 @@ class FileModuleCacheEntry : public ModuleCacheEntry {
452452
sys::fs::remove(OutputPath);
453453
// Cache is enabled, hard-link the entry (or copy if hard-link fails).
454454
std::string CacheEntryPath = getEntryPath();
455-
auto Err = sys::fs::create_hard_link(CacheEntryPath, OutputPath);
456-
if (!Err)
457-
return Error::success();
458-
// Hard linking failed, try to copy.
459-
Err = sys::fs::copy_file(CacheEntryPath, OutputPath);
460-
if (!Err)
461-
return Error::success();
462-
// Copy failed (could be because the CacheEntry was removed from the cache
463-
// in the meantime by another process), fall back and try to write down the
464-
// buffer to the output.
465-
errs() << "remark: can't link or copy from cached entry '" << CacheEntryPath
466-
<< "' to '" << OutputPath << "'\n";
455+
if (!CacheEntryPath.empty()) {
456+
auto Err = sys::fs::create_hard_link(CacheEntryPath, OutputPath);
457+
if (!Err)
458+
return Error::success();
459+
// Hard linking failed, try to copy.
460+
Err = sys::fs::copy_file(CacheEntryPath, OutputPath);
461+
if (!Err)
462+
return Error::success();
463+
// Copy failed (could be because the CacheEntry was removed from the cache
464+
// in the meantime by another process), fall back and try to write down
465+
// the buffer to the output.
466+
errs() << "remark: can't link or copy from cached entry '"
467+
<< CacheEntryPath << "' to '" << OutputPath << "'\n";
468+
}
467469
// Fallback to default.
468470
return ModuleCacheEntry::writeObject(OutputBuffer, OutputPath);
469471
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; No hash produced, empty file module entry.
2+
; RUN: opt -module-summary %s -o %t.bc
3+
4+
; RUN: rm -rf %t.cache.noindex && mkdir %t.cache.noindex
5+
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t.bc \
6+
; RUN: -thinlto-cache-dir %t.cache.noindex -thinlto-save-objects %t.save.noindex | FileCheck %s --allow-empty
7+
8+
; CHECK-NOT: remarks
9+
10+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
11+
target triple = "x86_64-apple-macosx10.11.0"
12+
13+
define void @globalfunc() #0 {
14+
entry:
15+
ret void
16+
}

0 commit comments

Comments
 (0)