@@ -691,7 +691,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
691691 Ok ( ( ) )
692692 }
693693
694- fn add_extern_static (
694+ pub ( crate ) fn add_extern_static (
695695 this : & mut MiriInterpCx < ' mir , ' tcx > ,
696696 name : & str ,
697697 ptr : Pointer < Option < Provenance > > ,
@@ -701,75 +701,6 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
701701 this. machine . extern_statics . try_insert ( Symbol :: intern ( name) , ptr) . unwrap ( ) ;
702702 }
703703
704- fn alloc_extern_static (
705- this : & mut MiriInterpCx < ' mir , ' tcx > ,
706- name : & str ,
707- val : ImmTy < ' tcx , Provenance > ,
708- ) -> InterpResult < ' tcx > {
709- let place = this. allocate ( val. layout , MiriMemoryKind :: ExternStatic . into ( ) ) ?;
710- this. write_immediate ( * val, & place) ?;
711- Self :: add_extern_static ( this, name, place. ptr ( ) ) ;
712- Ok ( ( ) )
713- }
714-
715- /// Sets up the "extern statics" for this machine.
716- fn init_extern_statics ( this : & mut MiriInterpCx < ' mir , ' tcx > ) -> InterpResult < ' tcx > {
717- // "__rust_no_alloc_shim_is_unstable"
718- let val = ImmTy :: from_int ( 0 , this. machine . layouts . u8 ) ;
719- Self :: alloc_extern_static ( this, "__rust_no_alloc_shim_is_unstable" , val) ?;
720-
721- match this. tcx . sess . target . os . as_ref ( ) {
722- "linux" => {
723- // "environ"
724- Self :: add_extern_static (
725- this,
726- "environ" ,
727- this. machine . env_vars . environ . as_ref ( ) . unwrap ( ) . ptr ( ) ,
728- ) ;
729- // A couple zero-initialized pointer-sized extern statics.
730- // Most of them are for weak symbols, which we all set to null (indicating that the
731- // symbol is not supported, and triggering fallback code which ends up calling a
732- // syscall that we do support).
733- for name in & [ "__cxa_thread_atexit_impl" , "getrandom" , "statx" , "__clock_gettime64" ]
734- {
735- let val = ImmTy :: from_int ( 0 , this. machine . layouts . usize ) ;
736- Self :: alloc_extern_static ( this, name, val) ?;
737- }
738- }
739- "freebsd" => {
740- // "environ"
741- Self :: add_extern_static (
742- this,
743- "environ" ,
744- this. machine . env_vars . environ . as_ref ( ) . unwrap ( ) . ptr ( ) ,
745- ) ;
746- }
747- "android" => {
748- // "signal" -- just needs a non-zero pointer value (function does not even get called),
749- // but we arrange for this to be callable anyway (it will then do nothing).
750- let layout = this. machine . layouts . const_raw_ptr ;
751- let ptr = this. fn_ptr ( FnVal :: Other ( DynSym :: from_str ( "signal" ) ) ) ;
752- let val = ImmTy :: from_scalar ( Scalar :: from_pointer ( ptr, this) , layout) ;
753- Self :: alloc_extern_static ( this, "signal" , val) ?;
754- // A couple zero-initialized pointer-sized extern statics.
755- // Most of them are for weak symbols, which we all set to null (indicating that the
756- // symbol is not supported, and triggering fallback code.)
757- for name in & [ "bsd_signal" ] {
758- let val = ImmTy :: from_int ( 0 , this. machine . layouts . usize ) ;
759- Self :: alloc_extern_static ( this, name, val) ?;
760- }
761- }
762- "windows" => {
763- // "_tls_used"
764- // This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
765- let val = ImmTy :: from_int ( 0 , this. machine . layouts . u8 ) ;
766- Self :: alloc_extern_static ( this, "_tls_used" , val) ?;
767- }
768- _ => { } // No "extern statics" supported on this target
769- }
770- Ok ( ( ) )
771- }
772-
773704 pub ( crate ) fn communicate ( & self ) -> bool {
774705 self . isolated_op == IsolatedOp :: Allow
775706 }
0 commit comments