Skip to content

Conversation

@bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Oct 23, 2025

This allows getting rid of all the argument mangling hacks as well as the exported_non_generic_symbols override hack by doing cargo build instead of cargo check. This is also a prerequisite for using native jit mode support in miri that I hope to add to rustc in the future to be used with cg_clif too.

Currently this still has two issues: The dummy backend can't build dylibs, but cargo tries to build libstd as dylib. (rust-lang/rust#148177) And required target features are not set by the dummy backend. Both of these require rustc side changes.

I'm opening this draft PR for early feedback on this approach before I spent time fixing these issues on the rustc side.

@rustbot rustbot added the S-waiting-on-author Status: Waiting for the PR author to address review comments label Oct 23, 2025
// `exported_non_generic_symbols` and `reachable_non_generics` provided by rustc always returns
// an empty result if `tcx.sess.opts.output_types.should_codegen()` is false.
// In addition we need to add #[used] symbols to exported_symbols for `lookup_link_section`.
local_providers.exported_non_generic_symbols = |tcx, LocalCrate| {
Copy link
Member Author

Choose a reason for hiding this comment

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

On second thought we may still need this for #[used].

/// Also disable the MIR pass that inserts an alignment check on every pointer dereference. Miri
/// does that too, and with a better error message.
pub const MIRI_DEFAULT_ARGS: &[&str] = &[
"-Zcodegen-backend=dummy",
Copy link
Member Author

Choose a reason for hiding this comment

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

The dummy codegen backend is a builtin codegen backend that is only capable of emitting rlibs containing the crate metadata. For every other crate type it emits an error after codegen. This is fine for miri as for --crate-type bin, miri exits before codegen.

bors added a commit to rust-lang/rust that referenced this pull request Oct 28, 2025
…apkin

Allow codegen backends to indicate which crate types they support

This way cargo will drop the unsupported crate types for crates that
specify multiple crate types.

This is a prerequisite for rust-lang/miri#4648.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 28, 2025
…, r=WaffleLapkin

Allow codegen backends to indicate which crate types they support

This way cargo will drop the unsupported crate types for crates that
specify multiple crate types.

This is a prerequisite for rust-lang/miri#4648.
rust-timer added a commit to rust-lang/rust that referenced this pull request Oct 28, 2025
Rollup merge of #148177 - bjorn3:codegen_backend_crate_types, r=WaffleLapkin

Allow codegen backends to indicate which crate types they support

This way cargo will drop the unsupported crate types for crates that
specify multiple crate types.

This is a prerequisite for rust-lang/miri#4648.
This allows getting rid of all the argument mangling hacks as well as
the exported_non_generic_symbols override hack by doing cargo build
instead of cargo check. This is also a prerequisite for using native jit
mode support in miri that I hope to add to rustc in the future to be
used with cg_clif too.

Currently this still has two issues: The dummy backend can't build
dylibs, but cargo tries to build libstd as dylib. And required target
features are not set by the dummy backend. Both of these require rustc
side changes.
@rustbot
Copy link
Collaborator

rustbot commented Oct 29, 2025

☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts.

} else {
// For all other kinds of tests, we can just add our flag.
cmd.arg("--emit=metadata");
cmd.arg("--emit=metadata,link");
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this still needed in the first place?

The library workspace sets this already nowadays.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 29, 2025
…es, r=JonathanBrouwer

Handle default features and -Ctarget-features in the dummy backend

This prevents a warning about ABI relevant target features not being set on x86 and arm. In addition it is required for miri to report correct features in is_*_feature_detected!() if miri switches to the dummy backend.

Required for rust-lang/miri#4648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: Waiting for the PR author to address review comments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants