rust-lang / rust-lang/rust

Special case `STATUS_STACK_BUFFER_OVERRUN` in linker exit code diagnostics

Open
#141,757 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

STATUS_STACK_BUFFER_OVERRUN isn't only used for stack cookie checks, but also __fastfail, which is used by abort(), making programs that abort exit with 0xc0000409. However, people generally aren't aware of that connection, as it's a Windows status code and searching for one of those yields pages and pages of articles with the quality of AI slop.

Take https://github.com/rust-lang/rust/issues/141626 as an example: The linker crashed due to a call to abort(), but it was initially misreported as "Link.exe overflowed it's stack." As we already emit special diagnostics if link.exe fails with exit codes outside of the known range, we could also print a special diagnostic for that exit code - and since that code already queries the registry, i.e. accesses resources external to rustc, it could maybe also look at the WER event log entries and read the fast-fail code out of the event log entry to disambiguate __fastfail from other error sources.

Current output
error: linking with `link.exe` failed: exit code: 0xc0000409
 |
 = note: <linker invocation>
 = note: some arguments are omitted. use `--verbose` to show all linker arguments
 = note:

note: `link.exe` returned an unexpected error

note: the Visual Studio build tools may need to be repaired using the Visual Studio installer

note: or a necessary component may be missing from the "C++ build tools" workload
Desired output
error: linking with `link.exe` failed: exit code: 0xc0000409
 |
 = note: <linker invocation>
 = note: some arguments are omitted. use `--verbose` to show all linker arguments
 = note:

note: `link.exe` returned an unexpected error

note: 0xc0000409 is `STATUS_STACK_BUFFER_OVERRUN`, which is used for abnormal program termination and does not necessarily indicate a stack buffer overrun.

note: the Visual Studio build tools may need to be repaired using the Visual Studio installer

note: or a necessary component may be missing from the "C++ build tools" workload
Rust Version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-pc-windows-msvc
release: 1.87.0
LLVM version: 20.1.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating rustc's existing linker exit-code diagnostics and the tests covering unexpected link.exe failures. Check how Windows status codes are represented, then add the requested 0xc0000409 explanation and a regression test for the displayed diagnostic. Done means the new note appears for this exit code without changing other linker-error messages.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system, tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.