Skip to content

Commit b60f75c

Browse files
committed
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.
1 parent 2fd855f commit b60f75c

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ codegen_ssa_ld64_unimplemented_modifier = `as-needed` modifier not implemented y
178178
179179
codegen_ssa_lib_def_write_failure = failed to write lib.def file: {$error}
180180
181+
codegen_ssa_link_exe_status_stack_buffer_overrun = 0xc0000409 is `STATUS_STACK_BUFFER_OVERRUN`
182+
.note = this may have been caused by a program abort and not a stack buffer overrun
183+
181184
codegen_ssa_link_exe_unexpected_error = `link.exe` returned an unexpected error
182185
183186
codegen_ssa_link_script_unavailable = can only use link script when linking with GNU-like linker

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,14 @@ fn link_natively(
880880
windows_registry::find_tool(&sess.target.arch, "link.exe").is_some();
881881

882882
sess.dcx().emit_note(errors::LinkExeUnexpectedError);
883+
884+
// STATUS_STACK_BUFFER_OVERRUN is also used for fast abnormal program termination, e.g. abort().
885+
// Emit a special diagnostic to let people know that this most likely doesn't indicate a stack buffer overrun.
886+
const STATUS_STACK_BUFFER_OVERRUN: i32 = 0xc0000409u32 as _;
887+
if code == STATUS_STACK_BUFFER_OVERRUN {
888+
sess.dcx().emit_note(errors::LinkExeStatusStackBufferOverrun);
889+
}
890+
883891
if is_vs_installed && has_linker {
884892
// the linker is broken
885893
sess.dcx().emit_note(errors::RepairVSBuildTools);

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,11 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
550550
#[diag(codegen_ssa_link_exe_unexpected_error)]
551551
pub(crate) struct LinkExeUnexpectedError;
552552

553+
#[derive(Diagnostic)]
554+
#[diag(codegen_ssa_link_exe_status_stack_buffer_overrun)]
555+
#[note]
556+
pub(crate) struct LinkExeStatusStackBufferOverrun;
557+
553558
#[derive(Diagnostic)]
554559
#[diag(codegen_ssa_repair_vs_build_tools)]
555560
pub(crate) struct RepairVSBuildTools;

0 commit comments

Comments
 (0)