[llvm] [BOLT] Check for write errors before keeping output file (PR #190359)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 3 09:01:43 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Rafael Auler (rafaelauler)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/190359.diff


1 Files Affected:

- (modified) bolt/lib/Rewrite/RewriteInstance.cpp (+7) 


``````````diff
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,

``````````

</details>


https://github.com/llvm/llvm-project/pull/190359


More information about the llvm-commits mailing list