@@ -272,8 +272,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
272
272
fn find_foreign_static (
273
273
tcx : TyCtxt < ' tcx > ,
274
274
def_id : DefId ,
275
- _memory_extra : & MemoryExtra ,
276
- ) -> InterpResult < ' tcx , Cow < ' tcx , Allocation > > {
275
+ id : AllocId ,
276
+ memory_extra : & MemoryExtra ,
277
+ ) -> InterpResult < ' tcx , Cow < ' tcx , Allocation < Tag , AllocExtra > > > {
277
278
let attrs = tcx. get_attrs ( def_id) ;
278
279
let link_name = match attr:: first_attr_value_str_by_name ( & attrs, sym:: link_name) {
279
280
Some ( name) => name. as_str ( ) ,
@@ -285,11 +286,22 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
285
286
// This should be all-zero, pointer-sized.
286
287
let size = tcx. data_layout . pointer_size ;
287
288
let data = vec ! [ 0 ; size. bytes( ) as usize ] ;
288
- Allocation :: from_bytes ( & data, tcx. data_layout . pointer_align . abi )
289
+ // We got tcx memory. Let the machine initialize its "extra" stuff.
290
+ let ( alloc, tag) = Self :: init_allocation_extra (
291
+ memory_extra,
292
+ id, // always use the ID we got as input, not the "hidden" one.
293
+ Cow :: Owned ( Allocation :: from_bytes ( & data, tcx. data_layout . pointer_align . abi ) ) ,
294
+ Self :: STATIC_KIND . map ( MemoryKind :: Machine ) ,
295
+ ) ;
296
+ debug_assert_eq ! ( tag, Self :: tag_static_base_pointer( memory_extra, id) ) ;
297
+ alloc
298
+ }
299
+ "environ" => {
300
+ Cow :: Owned ( memory_extra. environ . as_ref ( ) . cloned ( ) . unwrap ( ) )
289
301
}
290
302
_ => throw_unsup_format ! ( "can't access foreign static: {}" , link_name) ,
291
303
} ;
292
- Ok ( Cow :: Owned ( alloc) )
304
+ Ok ( alloc)
293
305
}
294
306
295
307
#[ inline( always) ]
0 commit comments