Skip to content

Commit 44a56f2

Browse files
committed
Improve diagnostic for linker abort exit code 0xc0000409 (STATUS_STACK_BUFFER_OVERRUN)
1 parent d41e12f commit 44a56f2

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ codegen_ssa_ld64_unimplemented_modifier = `as-needed` modifier not implemented y
176176
177177
codegen_ssa_lib_def_write_failure = failed to write lib.def file: {$error}
178178
179+
codegen_ssa_link_exe_fastfail_abort_note = This may be caused by Windows `__fastfail` termination, such as an `abort()` call, and does not necessarily indicate a stack buffer overrun.
180+
181+
codegen_ssa_link_exe_fastfail_status = 0xc0000409 is `STATUS_STACK_BUFFER_OVERRUN`
182+
179183
codegen_ssa_link_exe_unexpected_error = `link.exe` returned an unexpected error
180184
181185
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+
// 0xc0000409 (`STATUS_STACK_BUFFER_OVERRUN`) is also used by `abort()` via `__fastfail`. Not necessarily a buffer overrun.
885+
// See <https://devblogs.microsoft.com/oldnewthing/20190108-00/?p=100655>
886+
const STATUS_STACK_BUFFER_OVERRUN: i32 = 0xC0000409u32 as i32; // = -1073740791
887+
if code == STATUS_STACK_BUFFER_OVERRUN {
888+
sess.dcx().emit_note(errors::LinkExeFastFailAbort);
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
@@ -543,6 +543,11 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
543543
#[diag(codegen_ssa_link_exe_unexpected_error)]
544544
pub(crate) struct LinkExeUnexpectedError;
545545

546+
#[derive(Diagnostic)]
547+
#[diag(codegen_ssa_link_exe_fastfail_status)]
548+
#[note(codegen_ssa_link_exe_fastfail_abort_note)]
549+
pub(crate) struct LinkExeFastFailAbort;
550+
546551
#[derive(Diagnostic)]
547552
#[diag(codegen_ssa_repair_vs_build_tools)]
548553
pub(crate) struct RepairVSBuildTools;

0 commit comments

Comments
 (0)