Skip to content

Add diagnostic explaining STATUS_STACK_BUFFER_OVERRUN not only being used for stack buffer overruns if link.exe exits with that exit code #141828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_ssa/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ codegen_ssa_ld64_unimplemented_modifier = `as-needed` modifier not implemented y

codegen_ssa_lib_def_write_failure = failed to write lib.def file: {$error}

codegen_ssa_link_exe_status_stack_buffer_overrun = 0xc0000409 is `STATUS_STACK_BUFFER_OVERRUN`
.note = this may have been caused by a program abort and not a stack buffer overrun

codegen_ssa_link_exe_unexpected_error = `link.exe` returned an unexpected error

codegen_ssa_link_script_unavailable = can only use link script when linking with GNU-like linker
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,14 @@ fn link_natively(
windows_registry::find_tool(&sess.target.arch, "link.exe").is_some();

sess.dcx().emit_note(errors::LinkExeUnexpectedError);

// STATUS_STACK_BUFFER_OVERRUN is also used for fast abnormal program termination, e.g. abort().
// Emit a special diagnostic to let people know that this most likely doesn't indicate a stack buffer overrun.
const STATUS_STACK_BUFFER_OVERRUN: i32 = 0xc0000409u32 as _;
if code == STATUS_STACK_BUFFER_OVERRUN {
sess.dcx().emit_note(errors::LinkExeStatusStackBufferOverrun);
}

if is_vs_installed && has_linker {
// the linker is broken
sess.dcx().emit_note(errors::RepairVSBuildTools);
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_ssa/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,11 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
#[diag(codegen_ssa_link_exe_unexpected_error)]
pub(crate) struct LinkExeUnexpectedError;

#[derive(Diagnostic)]
#[diag(codegen_ssa_link_exe_status_stack_buffer_overrun)]
#[note]
pub(crate) struct LinkExeStatusStackBufferOverrun;

#[derive(Diagnostic)]
#[diag(codegen_ssa_repair_vs_build_tools)]
pub(crate) struct RepairVSBuildTools;
Expand Down
Loading