-
Couldn't load subscription status.
- Fork 400
[WIP] Use the dummy codegen backend #4648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
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.
| // `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| { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
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.