Skip to content

Commit c6d3179

Browse files
committed
Pass -Z no-codegen when invoking rustc.
We only need crate metadata and MIR, not the built object files, so this allows us to skip unecessary work when building `libstd`. It also prevents us from trying to codegen the `try` panicking intrinsic, which assumes that `libpanic_unwind` is being compiled for the target platform. We built `libpanic_unwind` with `cfg(miri)`, which may invalidate these assumptions (e.g. the `eh_catch_typeinfo` lang item is no longer defined).
1 parent 7bb3052 commit c6d3179

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ Several `-Z` flags are relevant for Miri:
172172
sets this flag per default.
173173
* `-Zmir-emit-retag` controls whether `Retag` statements are emitted. Miri
174174
enables this per default because it is needed for validation.
175+
* `-Zno-codegen` makes rustc skip generating LLVM IR for MIR (though it still
176+
writes out empty object files). This is needed to prevent rustc from trying
177+
to codegen certain panic-related intrinsics, which will not work with a
178+
`libpanic_unwind` compiled in `cfg(miri)` mode. It also speeds up
179+
building our custom libstd.
175180

176181
Moreover, Miri recognizes some environment variables:
177182

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ pub use crate::eval::{eval_main, create_ecx, MiriConfig};
5151
/// Insert rustc arguments at the beginning of the argument list that Miri wants to be
5252
/// set per default, for maximal validation power.
5353
pub fn miri_default_args() -> &'static [&'static str] {
54-
&["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0", "--cfg=miri"]
54+
&["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0", "-Zno-codegen", "--cfg=miri"]
5555
}

0 commit comments

Comments
 (0)