diff options
| author | George Tokmaji <tokmajigeorge@gmail.com> | 2025-05-31 21:18:41 +0200 |
|---|---|---|
| committer | George Tokmaji <tokmajigeorge@gmail.com> | 2025-08-08 00:16:53 +0200 |
| commit | b60f75c9261e0968fbb6f3aa435660db189e0ab5 (patch) | |
| tree | 6a1f76895f9816fd1e0886717d2ed78a967eaa19 | |
| parent | 2fd855fbfc8239285aa2d596f76a8cc75e17ce02 (diff) | |
| download | rust-b60f75c9261e0968fbb6f3aa435660db189e0ab5.tar.gz rust-b60f75c9261e0968fbb6f3aa435660db189e0ab5.zip | |
Add diagnostic explaining STATUS_STACK_BUFFER_OVERRUN not only being
used for stack buffer overruns if link.exe exits with that exit code `STATUS_STACK_BUFFER_OVERRUN` is also used for fast abnormal program termination, e.g. by abort(). Emit a special diagnostic to let people know that this most likely doesn't indicate a stack buffer overrun.
| -rw-r--r-- | compiler/rustc_codegen_ssa/messages.ftl | 3 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/errors.rs | 5 |
3 files changed, 16 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index a70d0011d16..53a52736a97 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -178,6 +178,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 diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b69fbf61185..c82af3d9d1e 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -880,6 +880,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); diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index 3d787d8bdbd..9ef1473e538 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -551,6 +551,11 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> { 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; |
