Rustc does not cleanup incomplete output files when interrupted by signal
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
Rustc does not cleanup incomplete output files that are being outputed by rustc,
when rustc is interrupted by a catchable signal such as SIGTERM.
This does not match the behavior of gcc and clang,
where incomplete generated output files are always removed when the program exits or signal received.
This behavior is not friendly to developer, where interrupt the build of project is not an uncommon thing.
This also causes many not easy to reproduce issues, especially when Rust incremental build is enabled,
such as:
- #142858
This is also not good for incremental compilation that an invalid output may be considered to be up-to-date by GNU Make.
How to reproduce
Write code which is fast to compile, but output file is large. Name it as main.rs
I test the reproduce in CentOS7 and WSL2 with ubuntu 22.04
fn main() {
// Generate a large static string at runtime
let large_string = "A".repeat(1_000_000_000);
println!("{}", &large_string[..10]);
}
Compile the file and immediately send SIGTERM to rustc before compilation done
rm -f main; rustc main.rs & sleep 0.2; pkill -f rustc; ls -l
You may need to adjust the time of sleep, or try several times
It is possible that an incomplete output of main with size of 0 is generated with several .rcgu.o files
Existing implementation in other compiler
LLVM has a class llvm::ToolOutputFile that is used to generate compiler output files.
When this class is constructed, the filename is registered in a global list.
When the program exits or signal occurs, all files in the list are removed.
llvm::ToolOutputFile has a keep method to remove the file from the list.
The file is also removed if dtor of llvm::ToolOutputFile is called without calling keep() method before
Meta
rustc --version --verbose:
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing rustc's output-file handling and its response to catchable signals; the issue does not name a source file or test. Reproduce with the provided large-string example and SIGTERM command, then verify that interrupted compilation removes incomplete main and .rcgu.o outputs without removing completed outputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100