Skip to content

nostd libc not link #32661

Closed
Closed
@adjivas

Description

@adjivas

I tried this code:

  • src/main.rs:
#![feature(lang_items)]
#![feature(start)]
#![no_std]

extern crate libc;

#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
    let buffer: [u8; 1] = [0u8];

    unsafe {
        libc::read(0, buffer.as_ptr() as *mut libc::c_void, 1);
    }

    let character: u8 = unsafe { *buffer.as_ptr() } as u8;
    let _ = 255u8 - character; // The line problem.

    0
}

#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
  • Cargo.toml:
[package]
name = "nostd"
version = "0.1.0"
authors = ["adjivas <[email protected]>"]

[profile.release]
lto = true

[dependencies.libc]
version = "*"
default-features = false

I expected to see this happen:

$ cargo rustc -- -Z force-overflow-checks=off
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading libc v0.2.9
   Compiling libc v0.2.9
   Compiling nostd v0.1.0 (file:///home/travis/build/adjivas/nostd)
The command "cargo rustc -- -Z force-overflow-checks=off" exited with 0.
$ nm ./target/debug/nostd | grep " U "
                 U __libc_start_main@@GLIBC_2.2.5
                 U memset@@GLIBC_2.2.5
                 U read@@GLIBC_2.2.5

Instead, this happened:

$ cargo rustc -- -Z force-overflow-checks=off
    Updating registry `https://github.com/rust-lang/crates.io-index`
 Downloading libc v0.2.9
   Compiling libc v0.2.9
   Compiling nostd v0.1.0 (file:///home/travis/build/adjivas/nostd)
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/travis/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/travis/build/adjivas/nostd/target/debug/nostd.0.o" "-o" "/home/travis/build/adjivas/nostd/target/debug/nostd" "-Wl,--gc-sections" "-pie" "-nodefaultlibs" "-L" "/home/travis/build/adjivas/nostd/target/debug" "-L" "/home/travis/build/adjivas/nostd/target/debug/deps" "-L" "/home/travis/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "/home/travis/build/adjivas/nostd/target/debug/deps/liblibc-00ad8a4a4c184a2d.rlib" "/home/travis/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-18402db3.rlib" "-l" "compiler-rt"
note: /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x12): undefined reference to `__libc_csu_fini'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x19): undefined reference to `__libc_csu_init'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x25): undefined reference to `__libc_start_main'
/home/travis/build/adjivas/nostd/target/debug/nostd.0.o: In function `nostd::start::hd7b9118d84e1f51b':
/home/travis/build/adjivas/nostd/src/main.rs:8: undefined reference to `memset'
/home/travis/build/adjivas/nostd/src/main.rs:12: undefined reference to `read'

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