Skip to content

Commit 85acaca

Browse files
committed
tag foreign statics eagerly
1 parent 51cf85f commit 85acaca

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/machine.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
272272
fn find_foreign_static(
273273
tcx: TyCtxt<'tcx>,
274274
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>>> {
277278
let attrs = tcx.get_attrs(def_id);
278279
let link_name = match attr::first_attr_value_str_by_name(&attrs, sym::link_name) {
279280
Some(name) => name.as_str(),
@@ -285,11 +286,22 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
285286
// This should be all-zero, pointer-sized.
286287
let size = tcx.data_layout.pointer_size;
287288
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())
289301
}
290302
_ => throw_unsup_format!("can't access foreign static: {}", link_name),
291303
};
292-
Ok(Cow::Owned(alloc))
304+
Ok(alloc)
293305
}
294306

295307
#[inline(always)]

src/shims/env.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ impl EnvVars {
4444
}
4545
ecx.memory.mark_immutable(environ_place.ptr.assert_ptr().alloc_id).unwrap();
4646
// A pointer to that place corresponds to the `environ` static.
47-
let environ_alloc = ecx.memory.get_raw(environ_place.ptr.assert_ptr().alloc_id).unwrap().clone();
47+
let environ_ptr = ecx.force_ptr(environ_place.ptr).unwrap();
48+
let environ_alloc = ecx.memory.get_raw(environ_ptr.alloc_id).unwrap().clone();
4849
ecx.memory.extra.environ = Some(environ_alloc);
4950
}
5051
}

0 commit comments

Comments
 (0)