Skip to content

Commit 1bc7660

Browse files
authored
Unrolled build for #141828
Rollup merge of #141828 - Fulgen301:status-stack-buffer-overrun-diagnostic, r=wesleywiser 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. This doesn't look up the crash report in the event log to determine what the fast fail error code is. This is due to the way crashes are logged: When a process crash happens, the system logs an "Application Error" event, which contains the exit code and the process ID, but not the fast fail error code. A second event by Windows Error Reporting does contain that fast fail code, but not the process ID - but that event is not emitted at process exit, but when WER has dealt with it (on my system, it happens roughly two seconds later), so querying the code would have to read the `IntegratorReportId`, wait two seconds or potentially longer for the WER event with the same `ReportID`, and read out the code. (Also, that second event doesn't happen if WER is disabled.) Fixes #100519.
2 parents 2de2456 + 7e5acb9 commit 1bc7660

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ codegen_ssa_ld64_unimplemented_modifier = `as-needed` modifier not implemented y
180180
181181
codegen_ssa_lib_def_write_failure = failed to write lib.def file: {$error}
182182
183+
codegen_ssa_link_exe_status_stack_buffer_overrun = 0xc0000409 is `STATUS_STACK_BUFFER_OVERRUN`
184+
.abort_note = this may have been caused by a program abort and not a stack buffer overrun
185+
.event_log_note = consider checking the Application Event Log for Windows Error Reporting events to see the fail fast error code
186+
183187
codegen_ssa_link_exe_unexpected_error = `link.exe` returned an unexpected error
184188
185189
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,18 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
550550
#[diag(codegen_ssa_link_exe_unexpected_error)]
551551
pub(crate) struct LinkExeUnexpectedError;
552552

553+
pub(crate) struct LinkExeStatusStackBufferOverrun;
554+
555+
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for LinkExeStatusStackBufferOverrun {
556+
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
557+
let mut diag =
558+
Diag::new(dcx, level, fluent::codegen_ssa_link_exe_status_stack_buffer_overrun);
559+
diag.note(fluent::codegen_ssa_abort_note);
560+
diag.note(fluent::codegen_ssa_event_log_note);
561+
diag
562+
}
563+
}
564+
553565
#[derive(Diagnostic)]
554566
#[diag(codegen_ssa_repair_vs_build_tools)]
555567
pub(crate) struct RepairVSBuildTools;

0 commit comments

Comments
 (0)