Skip to content

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

Closed
@ghost

Description

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::") => {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions