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. 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. You can test this PR right now by removing the crate-types = ["rlib", "dylib"] from ~/.rustup/toolchains/miri/lib/rustlib/src/rust/library/std/Cargo.toml.

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 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].

// Patch `--extern` filenames, since Cargo sometimes passes stub `.rlib` files:
// https://github.com/rust-lang/miri/issues/1705
if arg == "--extern" {
forward_patched_extern_arg(&mut args, &mut cmd);
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 forward_patched_extern_arg function can likely be removed as the fake lib file hack has been removed.

/// 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.

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