31
31
#![ panic_runtime]
32
32
#![ feature( panic_runtime) ]
33
33
34
+ // `real_imp` is unused with Miri, so silence warnings.
35
+ #![ cfg_attr( miri, allow( dead_code) ) ]
36
+
34
37
use alloc:: boxed:: Box ;
35
38
use core:: any:: Any ;
36
39
use core:: panic:: BoxMeUp ;
37
40
38
41
cfg_if:: cfg_if! {
39
42
if #[ cfg( target_os = "emscripten" ) ] {
40
43
#[ path = "emcc.rs" ]
41
- mod imp ;
44
+ mod real_imp ;
42
45
} else if #[ cfg( target_arch = "wasm32" ) ] {
43
46
#[ path = "dummy.rs" ]
44
- mod imp ;
47
+ mod real_imp ;
45
48
} else if #[ cfg( target_os = "hermit" ) ] {
46
49
#[ path = "hermit.rs" ]
47
- mod imp ;
50
+ mod real_imp ;
48
51
} else if #[ cfg( all( target_env = "msvc" , target_arch = "aarch64" ) ) ] {
49
52
#[ path = "dummy.rs" ]
50
- mod imp ;
53
+ mod real_imp ;
51
54
} else if #[ cfg( target_env = "msvc" ) ] {
52
55
#[ path = "seh.rs" ]
53
- mod imp ;
56
+ mod real_imp ;
54
57
} else {
55
58
// Rust runtime's startup objects depend on these symbols, so make them public.
56
59
#[ 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:: * ;
58
61
#[ 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" ]
59
72
mod imp;
73
+ } else {
74
+ // Use the real runtime.
75
+ use real_imp as imp;
60
76
}
61
77
}
62
78
@@ -81,12 +97,5 @@ pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
81
97
let payload = payload as * mut & mut dyn BoxMeUp ;
82
98
let payload = ( * payload) . take_box ( ) ;
83
99
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
-
91
100
imp:: panic ( Box :: from_raw ( payload) )
92
101
}
0 commit comments