@@ -18,7 +18,7 @@ use rustc_session::config::EntryFnType;
18
18
use crate :: concurrency:: GenmcCtx ;
19
19
use crate :: concurrency:: thread:: TlsAllocAction ;
20
20
use crate :: diagnostics:: report_leaks;
21
- use crate :: shims:: { ctor , tls} ;
21
+ use crate :: shims:: { global_ctor , tls} ;
22
22
use crate :: * ;
23
23
24
24
#[ derive( Copy , Clone , Debug ) ]
@@ -219,9 +219,11 @@ impl Default for MiriConfig {
219
219
#[ derive( Debug ) ]
220
220
enum MainThreadState < ' tcx > {
221
221
GlobalCtors {
222
- ctor_state : ctor:: GlobalCtorState < ' tcx > ,
222
+ ctor_state : global_ctor:: GlobalCtorState < ' tcx > ,
223
+ /// The main function to call.
223
224
entry_id : DefId ,
224
225
entry_type : MiriEntryFnType ,
226
+ /// Arguments passed to `main`.
225
227
argc : ImmTy < ' tcx > ,
226
228
argv : ImmTy < ' tcx > ,
227
229
} ,
@@ -324,12 +326,19 @@ pub fn create_ecx<'tcx>(
324
326
MiriMachine :: new ( config, layout_cx, genmc_ctx) ,
325
327
) ;
326
328
327
- // First argument is constructed later, because it's skipped for `miri_start.`
329
+ // Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
330
+ let sentinel =
331
+ helpers:: try_resolve_path ( tcx, & [ "core" , "ascii" , "escape_default" ] , Namespace :: ValueNS ) ;
332
+ if !matches ! ( sentinel, Some ( s) if tcx. is_mir_available( s. def. def_id( ) ) ) {
333
+ tcx. dcx ( ) . fatal (
334
+ "the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing. \
335
+ Use `cargo miri setup` to prepare a sysroot that is suitable for Miri."
336
+ ) ;
337
+ }
328
338
329
- // Second argument ( argc): length of `config.args`.
339
+ // Compute argc and argv from `config.args`.
330
340
let argc =
331
341
ImmTy :: from_int ( i64:: try_from ( config. args . len ( ) ) . unwrap ( ) , ecx. machine . layouts . isize ) ;
332
- // Third argument (`argv`): created from `config.args`.
333
342
let argv = {
334
343
// Put each argument in memory, collect pointers.
335
344
let mut argvs = Vec :: < Immediate < Provenance > > :: with_capacity ( config. args . len ( ) ) ;
@@ -354,7 +363,7 @@ pub fn create_ecx<'tcx>(
354
363
ecx. write_immediate ( arg, & place) ?;
355
364
}
356
365
ecx. mark_immutable ( & argvs_place) ;
357
- // Store `argc` and `argv` for macOS `_NSGetArg{c,v}`.
366
+ // Store `argc` and `argv` for macOS `_NSGetArg{c,v}`, and for the GC to see them .
358
367
{
359
368
let argc_place =
360
369
ecx. allocate ( ecx. machine . layouts . isize , MiriMemoryKind :: Machine . into ( ) ) ?;
@@ -369,7 +378,7 @@ pub fn create_ecx<'tcx>(
369
378
ecx. machine . argv = Some ( argv_place. ptr ( ) ) ;
370
379
}
371
380
// Store command line as UTF-16 for Windows `GetCommandLineW`.
372
- {
381
+ if tcx . sess . target . os == "windows" {
373
382
// Construct a command string with all the arguments.
374
383
let cmd_utf16: Vec < u16 > = args_to_utf16_command_string ( config. args . iter ( ) ) ;
375
384
@@ -392,28 +401,20 @@ pub fn create_ecx<'tcx>(
392
401
393
402
// Some parts of initialization require a full `InterpCx`.
394
403
MiriMachine :: late_init ( & mut ecx, config, {
395
- let mut state = MainThreadState :: GlobalCtors {
404
+ let mut main_thread_state = MainThreadState :: GlobalCtors {
396
405
entry_id,
397
406
entry_type,
398
407
argc,
399
408
argv,
400
- ctor_state : ctor :: GlobalCtorState :: default ( ) ,
409
+ ctor_state : global_ctor :: GlobalCtorState :: default ( ) ,
401
410
} ;
402
411
403
412
// Cannot capture anything GC-relevant here.
404
- Box :: new ( move |m| state. on_main_stack_empty ( m) )
413
+ // `argc` and `argv` *are* GC_relevant, but they also get stored in `machine.argc` and
414
+ // `machine.argv` so we are good.
415
+ Box :: new ( move |m| main_thread_state. on_main_stack_empty ( m) )
405
416
} ) ?;
406
417
407
- // Make sure we have MIR. We check MIR for some stable monomorphic function in libcore.
408
- let sentinel =
409
- helpers:: try_resolve_path ( tcx, & [ "core" , "ascii" , "escape_default" ] , Namespace :: ValueNS ) ;
410
- if !matches ! ( sentinel, Some ( s) if tcx. is_mir_available( s. def. def_id( ) ) ) {
411
- tcx. dcx ( ) . fatal (
412
- "the current sysroot was built without `-Zalways-encode-mir`, or libcore seems missing. \
413
- Use `cargo miri setup` to prepare a sysroot that is suitable for Miri."
414
- ) ;
415
- }
416
-
417
418
interp_ok ( ecx)
418
419
}
419
420
0 commit comments