[BOLT] Check for write errors before keeping output file (#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.
This commit is contained in:
Rafael Auler 2026-04-03 10:02:36 -07:00 committed by GitHub
parent 150042141c
commit 7da3a66c06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,