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

extern crate std; in a #![no_std] crate confuses Miri unless it's in the root module #1821

Closed
ghost opened this issue Jun 2, 2021 · 2 comments · Fixed by #1823
Closed

extern crate std; in a #![no_std] crate confuses Miri unless it's in the root module #1821

ghost opened this issue Jun 2, 2021 · 2 comments · Fixed by #1823

Comments

@ghost
Copy link

ghost commented Jun 2, 2021

This program:

#![no_std]

fn main() {
    extern crate std;
}

Causes this error in Miri (playground):

error: unsupported operation: can't call foreign function: signal
   --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/mod.rs:119:17
    |
119 |         assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't call foreign function: signal
    |
    = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
            
    = note: inside `main::std::sys::unix::init::reset_sigpipe` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/mod.rs:119:17
    = note: inside `main::std::sys::unix::init` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/mod.rs:62:5
    = note: inside `main::std::sys_common::rt::init` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/rt.rs:16:9
    = note: inside `main::std::rt::lang_start_internal` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:32:14
    = note: inside `main::std::rt::lang_start::<()>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:48:5

But the program runs fine if extern crate std; is in the root module or the crate is not #![no_std].

I encountered this issue when I was trying to access std by using extern crate std; in a #[test] of a #![no_std] crate.

I guess that this is because the stack frame is main::std::... in this case, while this code (cc #1263) only checks for std::...:

if this.frame().instance.to_string().starts_with("std::sys::unix::") => {

@RalfJung
Copy link
Member

RalfJung commented Jun 2, 2021

I guess that this is because the stack frame is main::std::... in this case, while this code (cc #1263) only checks for std::...:

Yes, I am pretty sure that's it.
How common is it to have extern crate not at the root module...?

@oli-obk
Copy link
Contributor

oli-obk commented Jun 2, 2021

How common is it to have extern crate not at the root module...?

serde does this a lot

ideally we'd use lang/diagonstic items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants