Skip to content

Commit 53f8175

Browse files
committed
Auto merge of rust-lang#3695 - RalfJung:no-libc-on-win, r=RalfJung
don't rely on libc existing on Windows Fixes rust-lang/miri#3692
2 parents f1a7941 + 8a657f9 commit 53f8175

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/tools/miri/src/helpers.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
273273

274274
/// Helper function to get a `libc` constant as a `Scalar`.
275275
fn eval_libc(&self, name: &str) -> Scalar {
276+
if self.eval_context_ref().tcx.sess.target.os == "windows" {
277+
panic!(
278+
"`libc` crate is not reliably available on Windows targets; Miri should not use it there"
279+
);
280+
}
276281
self.eval_path_scalar(&["libc", name])
277282
}
278283

@@ -316,6 +321,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
316321
/// Helper function to get the `TyAndLayout` of a `libc` type
317322
fn libc_ty_layout(&self, name: &str) -> TyAndLayout<'tcx> {
318323
let this = self.eval_context_ref();
324+
if this.tcx.sess.target.os == "windows" {
325+
panic!(
326+
"`libc` crate is not reliably available on Windows targets; Miri should not use it there"
327+
);
328+
}
319329
let ty = this
320330
.resolve_path(&["libc", name], Namespace::TypeNS)
321331
.ty(*this.tcx, ty::ParamEnv::reveal_all());
@@ -1048,7 +1058,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10481058
/// Always returns a `Vec<u32>` no matter the size of `wchar_t`.
10491059
fn read_wchar_t_str(&self, ptr: Pointer) -> InterpResult<'tcx, Vec<u32>> {
10501060
let this = self.eval_context_ref();
1051-
let wchar_t = this.libc_ty_layout("wchar_t");
1061+
let wchar_t = if this.tcx.sess.target.os == "windows" {
1062+
// We don't have libc on Windows so we have to hard-code the type ourselves.
1063+
this.machine.layouts.u16
1064+
} else {
1065+
this.libc_ty_layout("wchar_t")
1066+
};
10521067
self.read_c_str_with_char_size(ptr, wchar_t.size, wchar_t.align.abi)
10531068
}
10541069

0 commit comments

Comments
 (0)