Skip to content

Use __fastfail() for crash() on Windows - #166175

Open
Jules-Bertholet wants to merge 2 commits into
rust-lang:mainfrom
Jules-Bertholet:fastfail
Open

Jules-Bertholet wants to merge 2 commits into
rust-lang:mainfrom
Jules-Bertholet:fastfail

Conversation

@Jules-Bertholet

@Jules-Bertholet Jules-Bertholet commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

__fastfail is the preferred way to quickly abort the process on this platform. Unlike ud2, it won't go through SEH.

See previously #149780

@rustbot label O-windows

@rustbot rustbot added A-process Area: `std::process` (note: `std::env` is A-env) O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 19, 2026
@rust-log-analyzer

This comment has been minimized.

Comment thread library/core/src/os/windows.rs Resolved
@Jules-Bertholet
Jules-Bertholet force-pushed the fastfail branch 2 times, most recently from ce5ad7e to aec71b0 Compare November 19, 2026 15:08
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Jules-Bertholet
Jules-Bertholet marked this pull request as ready for review November 19, 2026 19:38
@rustbot

rustbot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

Any special-casing of Miri in the standard library requires review.

cc @rust-lang/miri

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 19, 2026
@rustbot

rustbot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

r? @clarfonthey

rustbot has assigned @clarfonthey.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 38 candidates
  • Random selection from JohnTitor, Mark-Simulacrum, clarfonthey, maxdexh

///
/// <https://docs.microsoft.com/en-us/cpp/intrinsics/fastfail>
#[inline]
#[unstable(feature = "windows_fastfail", issue = "none")]

@RalfJung RalfJung Nov 19, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this meant to be an internal feature? Then it should be called something_internal to trigger the lint.

View changes since the review

@Jules-Bertholet Jules-Bertholet Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to consider putting it on a stabilization track, so that users can pass custom codes. (I don't have a strong opinion either way)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep it unstable for now anyway. I don't know if calling it __fastfail is the best name rather than without the two underscores, but I'm not going to nitpick here.

Comment thread library/core/src/process.rs Resolved
@RalfJung

RalfJung commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

The backend also invokes the intrinsic directly in a couple of places.
I think those are all "we found UB but we're being nice" so it doesn't matter that much to be consistent, but it's worth checking and updating comments (and possibly renaming methods) to make it clear that the intrinsic should not be directly invoked for anything that implements a "user-visible well-defined abort".

@rustbot

rustbot commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

I think those are all "we found UB but we're being nice"

It's also used for CFI mismatches. I think ideally that would be __fastfail(FAST_FAIL_GUARD_ICALL_CHECK_FAILURE) on Windows—that's what MSVC's CFI implementation does.

@RalfJung

Copy link
Copy Markdown
Member

CFI mismatches are UB. 🤷

If you think that's not the ideal choice there, maybe add a FIXME.

@Jules-Bertholet

Jules-Bertholet commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

CFI mismatches are UB.

Some are, but others are merely EB—is that not the plan?

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 27, 2026
@rust-bors

rust-bors Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#166671), which was unapproved.

View changes since this unapproval

@clarfonthey

Copy link
Copy Markdown
Contributor

Right, your issue was that the cfg_select! in os/windows.rs is enabled when documenting code, and thus could not be exhaustively matched when you're not running in miri, x86, or ARM.

I would just add a doc => unreachable!() branch.

@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 27, 2026

@RalfJung RalfJung Nov 27, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That.... works I guess but seems very hacky. It's definitely not how fallback bodies are meant to be used. They are called fallback bodies, after all -- this intrinsic is doing the exact opposite of "fallback" with them.

At the very least, every backend should have a comment explaining the strange logic there (where we avoid overwriting the intrinsic if it has a fallback body).

View changes since the review

@RalfJung

RalfJung commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

This approach only partially achieves the desired goal -- when the backend invokes abort_immediate, that will still generate the LLVM intrinsic, not fastfail. I don't see a significant advantage over the previous libs-only approach, and it has the downside of abusing fallback bodies in unintended ways.

My proposal of a lang item would have avoided all these issues. Why did you use this alternative instead?

@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

My proposal of a lang item would have avoided that issue. Why did you use this alternative instead?

I don't know how to ensure the lang item is codegenned. (By the time we get to the backend, that decision has already been made.)

@RalfJung

Copy link
Copy Markdown
Member

Somewhere we have a function that defines all the roots for the mono item collector. It already puts a bunch of special things in there. This lang item can be added there.

@RalfJung

Copy link
Copy Markdown
Member

It's fn collect_roots in compiler/rustc_monomorphize/src/collector.rs.

@RalfJung

RalfJung commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

This makes me wonder how that works for the lang items that cause panics -- those also have calls inserted by codegen, and I don't see special treatment for them in the mono item collector...

EDIT: oh...

mir::TerminatorKind::Assert { ref msg, .. } => match &**msg {
mir::AssertKind::BoundsCheck { .. } => {
push_mono_lang_item(self, LangItem::PanicBoundsCheck);
}
mir::AssertKind::MisalignedPointerDereference { .. } => {
push_mono_lang_item(self, LangItem::PanicMisalignedPointerDereference);
}
mir::AssertKind::NullPointerDereference => {
push_mono_lang_item(self, LangItem::PanicNullPointerDereference);
}
mir::AssertKind::NullReferenceConstructed => {
push_mono_lang_item(self, LangItem::PanicNullReferenceConstructed);
}
mir::AssertKind::InvalidEnumConstruction(_) => {
push_mono_lang_item(self, LangItem::PanicInvalidEnumConstruction);
}
_ => {
push_mono_lang_item(self, msg.panic_function());
}
},
mir::TerminatorKind::UnwindTerminate(reason) => {
push_mono_lang_item(self, reason.lang_item());
}

@rustbot

rustbot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Nov 27, 2026
@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@clarfonthey

Copy link
Copy Markdown
Contributor

(happy to also pass off to someone on compiler to do some better backend review)

@Jules-Bertholet

Copy link
Copy Markdown
Contributor Author

r? compiler

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Nov 28, 2026
@rustbot rustbot assigned oli-obk and unassigned clarfonthey Nov 28, 2026
@clarfonthey

Copy link
Copy Markdown
Contributor

Also to be clear on my requirements from a libs perspective: I don't think that intrinsics::abort_immediate should ever do anything different from core::process::crash, such that the latter is always just a thin wrapper over the former. But I don't particularly care about the means by which you modify the intrinsic on Windows just emit the desired assembly, and that's why I defer to compiler on the approach that's best for that.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-process Area: `std::process` (note: `std::env` is A-env) A-tidy Area: The tidy tool O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.