Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE when running tests in a no_std lib crate #2904

Open
saethlin opened this issue May 29, 2023 · 6 comments
Open

ICE when running tests in a no_std lib crate #2904

saethlin opened this issue May 29, 2023 · 6 comments
Labels
A-shims Area: This affects the external function shims C-bug Category: This is a bug. I-ICE Impact: makes Miri crash with some ICE

Comments

@saethlin
Copy link
Member

This crate comes with a aarch64-skyline-switch.json file, I feel like there's some sort of target mismatch when I blindly run cargo miri test on it. So on the one hand I'm not actually expecting tests to run or pass, but also we probably shouldn't ICE in std::rt?

https://crates.io/crates/nnsdk/0.3.0

thread 'rustc' panicked at 'failed to find required Rust item: ["libc", "_SC_PAGESIZE"]', src/tools/miri/src/helpers.rs:156:32
note: the place in the program where the ICE was triggered
   --> /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/os.rs:593:14
    |
593 |     unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize }
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: inside `std::sys::unix::os::page_size` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/os.rs:593:14: 593:47
    = note: inside `std::sys::unix::thread::guard::init` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/thread.rs:782:25: 782:40
    = note: inside `std::rt::init` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:99:26: 99:52
    = note: inside closure at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:147:42: 147:67
    = note: inside `std::panicking::r#try::do_call::<[closure@std::rt::lang_start_internal::{closure#1}], ()>` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:500:40: 500:43
    = note: inside `std::panicking::r#try::<(), [closure@std::rt::lang_start_internal::{closure#1}]>` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:464:19: 464:81
    = note: inside `std::panic::catch_unwind::<[closure@std::rt::lang_start_internal::{closure#1}], ()>` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:142:14: 142:33
    = note: inside `std::rt::lang_start_internal` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:147:5: 147:70
    = note: inside `std::rt::lang_start::<()>` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:165:17: 170:6
@saethlin saethlin added the I-ICE Impact: makes Miri crash with some ICE label May 29, 2023
@RalfJung
Copy link
Member

Are the crate sources on github somewhere or so?

cargo miri test without --target should ignore that target file. So somehow it looks like libc is missing? Is this a no_std situation?

@saethlin
Copy link
Member Author

The crate doesn't have a repo link and I can't find it on @jam1garner's GitHub page. I downloaded the sources from crates.io, for example using https://github.com/saethlin/miri-tools/blob/50412bc80fd5966e53e103bde987bad7107bebc9/cargo-download/src/main.rs

@jam1garner
Copy link

Don't have to time to look at this rn in case I have other insight but here's the repo link: https://github.com/ultimate-research/nnsdk-rs

@saethlin
Copy link
Member Author

Ah, perfect. I wasn't expecting any help from you, I think this is almost certainly just a Miri issue.

@RalfJung
Copy link
Member

Ah it is no_std indeed. Our sysconf shim doesn't really work in that case.

Fixing the ICE is fairly easy by being less panic-y around here. Actually making it work is harder though. Judging from the backtrace there actually is a std linked into the test care... I don't quite understand how no_std and unit tests interact.

@bjorn3
Copy link
Member

bjorn3 commented May 30, 2023

#![no_std] in unit tests will still inject extern crate test;, which in turn pulls in libstd as dependency, but it won't make it available as std::* I think.

@RalfJung RalfJung changed the title ICE in std::rt::init when listing tests in nnsdk ICE when running tests in a no_std lib crate Apr 18, 2024
@RalfJung RalfJung added C-bug Category: This is a bug. A-shims Area: This affects the external function shims labels Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-shims Area: This affects the external function shims C-bug Category: This is a bug. I-ICE Impact: makes Miri crash with some ICE
Projects
None yet
Development

No branches or pull requests

4 participants