[llvm] [BOLT] Check for write errors before keeping output file (PR #190359)
Rafael Auler via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 3 09:01:10 PDT 2026
https://github.com/rafaelauler created https://github.com/llvm/llvm-project/pull/190359
Summary:
When the disk runs out of space during output file writing, BOLT would crash with SIGSEGV/SIGABRT because raw_fd_ostream silently records write errors and only reports them via abort() in its destructor. This made it difficult to distinguish real BOLT bugs from infrastructure issues in production monitoring.
Add an explicit error check on the output stream before calling Out->keep(), so BOLT exits cleanly with exit code 1 and a clear error message instead.
Test: manually verified with a full filesystem that BOLT now prints "BOLT-ERROR: failed to write output file: No space left on device" and exits with code 1.
>From 59f9c390ab3e45d90de1bd571370ef68f8efc3be Mon Sep 17 00:00:00 2001
From: Rafael Auler <rafaelauler at fb.com>
Date: Fri, 3 Apr 2026 08:31:27 -0700
Subject: [PATCH] [BOLT] Check for write errors before keeping output file
Summary:
When the disk runs out of space during output file writing,
BOLT would crash with SIGSEGV/SIGABRT because raw_fd_ostream
silently records write errors and only reports them via abort()
in its destructor. This made it difficult to distinguish real
BOLT bugs from infrastructure issues in production monitoring.
Add an explicit error check on the output stream before calling
Out->keep(), so BOLT exits cleanly with exit code 1 and a clear
error message instead.
Test: manually verified with a full filesystem that BOLT now
prints "BOLT-ERROR: failed to write output file: No space left
on device" and exits with code 1.
---
bolt/lib/Rewrite/RewriteInstance.cpp | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index b036b2e8d42dd..417e93e780062 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -6345,6 +6345,13 @@ void RewriteInstance::rewriteFile() {
BC->printSections(BC->outs());
}
+ if (OS.has_error()) {
+ BC->errs() << "BOLT-ERROR: failed to write output file '"
+ << opts::OutputFilename << "': " << OS.error().message() << "\n";
+ OS.clear_error();
+ exit(1);
+ }
+
Out->keep();
EC = sys::fs::setPermissions(
opts::OutputFilename,
More information about the llvm-commits
mailing list