Closed
Description
when compiling for x86_64-unknown-linux-none
, the static items in the following code snippet have null pointers as address. The inline versions work as expected. The exit code of the program is 10
.
#![no_std]
#![no_main]
use syscalls::Sysno;
static SLICE: &[u8; 5] = b"hello";
static STRING:&str = "hello";
#[no_mangle]
pub extern "C" fn _start() -> ! {
let static_slice = SLICE.as_ptr().is_null() as usize;
let inline_slice = b"hello".as_ptr().is_null() as usize;
let static_str = STRING.as_ptr().is_null() as usize;
let inline_str = "hello".as_ptr().is_null() as usize;
let exit_code = static_slice<<3|inline_slice<<2|static_str<<1|inline_str;
unsafe {
syscalls::syscall1(Sysno::exit,exit_code).unwrap();
}
loop{}
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop{}
}
Meta
rustc --version --verbose
:
rustc 1.85.0-nightly (409998c4e 2024-12-24)
binary: rustc
commit-hash: 409998c4e8cae45344fd434b358b697cc93870d0
commit-date: 2024-12-24
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6
cargo config:
[build]
target = "x86_64-unknown-linux-none"
[unstable]
build-std = ["core"]