Skip to content

Commit 92096f4

Browse files
committed
[ThinLTO] Fix FileModuleCacheEntry
It assumed cache is always written before the object file.
1 parent 5893821 commit 92096f4

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -467,36 +467,24 @@ class FileModuleCacheEntry : public ModuleCacheEntry {
467467
}
468468

469469
void write(const MemoryBuffer &OutputBuffer, std::function<void()> Cb) final {
470-
if (auto Err = llvm::writeToOutput(
471-
EntryPath, [&OutputBuffer](llvm::raw_ostream &OS) -> llvm::Error {
472-
OS << OutputBuffer.getBuffer();
473-
return llvm::Error::success();
474-
}))
475-
report_fatal_error(llvm::formatv("ThinLTO: Can't write file {0}: {1}",
476-
EntryPath,
477-
toString(std::move(Err)).c_str()));
478-
return Cb();
470+
// FIXME: If we knew OutputPath, we could just create hardlink.
471+
auto Err = llvm::writeToOutput(
472+
EntryPath, [&OutputBuffer](llvm::raw_ostream &OS) -> llvm::Error {
473+
OS << OutputBuffer.getBuffer();
474+
return llvm::Error::success();
475+
});
476+
if (Err)
477+
llvm::errs() << llvm::toString(std::move(Err)) << "\n";
478+
Cb();
479479
}
480480

481481
Error writeObject(const MemoryBuffer &OutputBuffer,
482482
StringRef OutputPath) final {
483-
// Clear output file if exists for hard-linking.
484-
sys::fs::remove(OutputPath);
485-
// Hard-link the entry (or copy if hard-link fails).
486-
auto Err = sys::fs::create_hard_link(EntryPath, OutputPath);
487-
if (!Err)
488-
return Error::success();
489-
// Hard linking failed, try to copy.
490-
Err = sys::fs::copy_file(EntryPath, OutputPath);
491-
if (!Err)
492-
return Error::success();
493-
// Copy failed (could be because the CacheEntry was removed from the cache
494-
// in the meantime by another process), fall back and try to write down
495-
// the buffer to the output.
496-
errs() << "remark: can't link or copy from cached entry '" << EntryPath
497-
<< "' to '" << OutputPath << "'\n";
498-
// Fallback to default.
499-
return ModuleCacheEntry::writeObject(OutputBuffer, OutputPath);
483+
return llvm::writeToOutput(
484+
OutputPath, [&OutputBuffer](llvm::raw_ostream &OS) -> llvm::Error {
485+
OS << OutputBuffer.getBuffer();
486+
return llvm::Error::success();
487+
});
500488
}
501489

502490
std::optional<std::unique_ptr<MemoryBuffer>> getMappedBuffer() final {

0 commit comments

Comments
 (0)