@@ -232,13 +232,15 @@ pub struct PrimitiveLayouts<'tcx> {
232232 pub u32 : TyAndLayout < ' tcx > ,
233233 pub usize : TyAndLayout < ' tcx > ,
234234 pub bool : TyAndLayout < ' tcx > ,
235- pub mut_raw_ptr : TyAndLayout < ' tcx > ,
235+ pub mut_raw_ptr : TyAndLayout < ' tcx > , // *mut ()
236+ pub const_raw_ptr : TyAndLayout < ' tcx > , // *const ()
236237}
237238
238239impl < ' mir , ' tcx : ' mir > PrimitiveLayouts < ' tcx > {
239240 fn new ( layout_cx : LayoutCx < ' tcx , TyCtxt < ' tcx > > ) -> Result < Self , LayoutError < ' tcx > > {
240241 let tcx = layout_cx. tcx ;
241242 let mut_raw_ptr = tcx. mk_ptr ( TypeAndMut { ty : tcx. types . unit , mutbl : Mutability :: Mut } ) ;
243+ let const_raw_ptr = tcx. mk_ptr ( TypeAndMut { ty : tcx. types . unit , mutbl : Mutability :: Not } ) ;
242244 Ok ( Self {
243245 unit : layout_cx. layout_of ( tcx. mk_unit ( ) ) ?,
244246 i8 : layout_cx. layout_of ( tcx. types . i8 ) ?,
@@ -251,6 +253,7 @@ impl<'mir, 'tcx: 'mir> PrimitiveLayouts<'tcx> {
251253 usize : layout_cx. layout_of ( tcx. types . usize ) ?,
252254 bool : layout_cx. layout_of ( tcx. types . bool ) ?,
253255 mut_raw_ptr : layout_cx. layout_of ( mut_raw_ptr) ?,
256+ const_raw_ptr : layout_cx. layout_of ( const_raw_ptr) ?,
254257 } )
255258 }
256259}
@@ -431,6 +434,17 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
431434 this. machine . extern_statics . try_insert ( Symbol :: intern ( name) , ptr) . unwrap ( ) ;
432435 }
433436
437+ fn alloc_extern_static (
438+ this : & mut MiriEvalContext < ' mir , ' tcx > ,
439+ name : & str ,
440+ val : ImmTy < ' tcx , Provenance > ,
441+ ) -> InterpResult < ' tcx > {
442+ let place = this. allocate ( val. layout , MiriMemoryKind :: ExternStatic . into ( ) ) ?;
443+ this. write_immediate ( * val, & place. into ( ) ) ?;
444+ Self :: add_extern_static ( this, name, place. ptr ) ;
445+ Ok ( ( ) )
446+ }
447+
434448 /// Sets up the "extern statics" for this machine.
435449 fn init_extern_statics ( this : & mut MiriEvalContext < ' mir , ' tcx > ) -> InterpResult < ' tcx > {
436450 match this. tcx . sess . target . os . as_ref ( ) {
@@ -447,10 +461,8 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
447461 // syscall that we do support).
448462 for name in & [ "__cxa_thread_atexit_impl" , "getrandom" , "statx" , "__clock_gettime64" ]
449463 {
450- let layout = this. machine . layouts . usize ;
451- let place = this. allocate ( layout, MiriMemoryKind :: ExternStatic . into ( ) ) ?;
452- this. write_scalar ( Scalar :: from_machine_usize ( 0 , this) , & place. into ( ) ) ?;
453- Self :: add_extern_static ( this, name, place. ptr ) ;
464+ let val = ImmTy :: from_int ( 0 , this. machine . layouts . usize ) ;
465+ Self :: alloc_extern_static ( this, name, val) ?;
454466 }
455467 }
456468 "freebsd" => {
@@ -461,13 +473,27 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
461473 this. machine . env_vars . environ . unwrap ( ) . ptr ,
462474 ) ;
463475 }
476+ "android" => {
477+ // "signal"
478+ let layout = this. machine . layouts . const_raw_ptr ;
479+ let dlsym = Dlsym :: from_str ( "signal" . as_bytes ( ) , & this. tcx . sess . target . os ) ?
480+ . expect ( "`signal` must be an actual dlsym on android" ) ;
481+ let ptr = this. create_fn_alloc_ptr ( FnVal :: Other ( dlsym) ) ;
482+ let val = ImmTy :: from_scalar ( Scalar :: from_pointer ( ptr, this) , layout) ;
483+ Self :: alloc_extern_static ( this, "signal" , val) ?;
484+ // A couple zero-initialized pointer-sized extern statics.
485+ // Most of them are for weak symbols, which we all set to null (indicating that the
486+ // symbol is not supported, and triggering fallback code.)
487+ for name in & [ "bsd_signal" ] {
488+ let val = ImmTy :: from_int ( 0 , this. machine . layouts . usize ) ;
489+ Self :: alloc_extern_static ( this, name, val) ?;
490+ }
491+ }
464492 "windows" => {
465493 // "_tls_used"
466494 // This is some obscure hack that is part of the Windows TLS story. It's a `u8`.
467- let layout = this. machine . layouts . u8 ;
468- let place = this. allocate ( layout, MiriMemoryKind :: ExternStatic . into ( ) ) ?;
469- this. write_scalar ( Scalar :: from_u8 ( 0 ) , & place. into ( ) ) ?;
470- Self :: add_extern_static ( this, "_tls_used" , place. ptr ) ;
495+ let val = ImmTy :: from_int ( 0 , this. machine . layouts . u8 ) ;
496+ Self :: alloc_extern_static ( this, "_tls_used" , val) ?;
471497 }
472498 _ => { } // No "extern statics" supported on this target
473499 }
0 commit comments