3131#![ panic_runtime]
3232#![ feature( panic_runtime) ]
3333
34+ // `real_imp` is unused with Miri, so silence warnings.
35+ #![ cfg_attr( miri, allow( dead_code) ) ]
36+
3437use alloc:: boxed:: Box ;
3538use core:: any:: Any ;
3639use core:: panic:: BoxMeUp ;
3740
3841cfg_if:: cfg_if! {
3942 if #[ cfg( target_os = "emscripten" ) ] {
4043 #[ path = "emcc.rs" ]
41- mod imp ;
44+ mod real_imp ;
4245 } else if #[ cfg( target_arch = "wasm32" ) ] {
4346 #[ path = "dummy.rs" ]
44- mod imp ;
47+ mod real_imp ;
4548 } else if #[ cfg( target_os = "hermit" ) ] {
4649 #[ path = "hermit.rs" ]
47- mod imp ;
50+ mod real_imp ;
4851 } else if #[ cfg( all( target_env = "msvc" , target_arch = "aarch64" ) ) ] {
4952 #[ path = "dummy.rs" ]
50- mod imp ;
53+ mod real_imp ;
5154 } else if #[ cfg( target_env = "msvc" ) ] {
5255 #[ path = "seh.rs" ]
53- mod imp ;
56+ mod real_imp ;
5457 } else {
5558 // Rust runtime's startup objects depend on these symbols, so make them public.
5659 #[ cfg( all( target_os="windows" , target_arch = "x86" , target_env="gnu" ) ) ]
57- pub use imp :: eh_frame_registry:: * ;
60+ pub use real_imp :: eh_frame_registry:: * ;
5861 #[ path = "gcc.rs" ]
62+ mod real_imp;
63+ }
64+ }
65+
66+ cfg_if:: cfg_if! {
67+ if #[ cfg( miri) ] {
68+ // Use the Miri runtime.
69+ // We still need to also load the normal runtime above, as rustc expects certain lang
70+ // items from there to be defined.
71+ #[ path = "miri.rs" ]
5972 mod imp;
73+ } else {
74+ // Use the real runtime.
75+ use real_imp as imp;
6076 }
6177}
6278
@@ -81,12 +97,5 @@ pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
8197 let payload = payload as * mut & mut dyn BoxMeUp ;
8298 let payload = ( * payload) . take_box ( ) ;
8399
84- // Miri panic support: cfg'd out of normal builds just to be sure.
85- // When going through normal codegen, `miri_start_panic` is a NOP, so the
86- // Miri-enabled sysroot still supports normal unwinding. But when executed in
87- // Miri, this line initiates unwinding.
88- #[ cfg( miri) ]
89- core:: intrinsics:: miri_start_panic ( payload) ;
90-
91100 imp:: panic ( Box :: from_raw ( payload) )
92101}
0 commit comments