@Suiseiseki@freesoftwareextremist.com @theorytoe@ak.kyaruc.moe @PurpCat@clubcyberia.co @EdBoatConnoisseur@poa.st The problem with the rust compiler is by default it embeds the entire rust standard library into the binary (without optimizing).
You can disable it with #![no_std] and use libc directly.
this is the hello world program with libc:#![no_std]
#![no_main]
use core::ffi::CStr;
#[no_mangle]
pub extern fn main(_argc: i32, _argv: *const *const core::ffi::c_char) -> i32 {
unsafe{libc::printf(CStr::from_bytes_with_nul_unchecked("hello world\n\0".as_bytes()).as_ptr());}
0
}
#[cfg(not(test))]
#[panic_handler]
fn panic(_:&core::panic::PanicInfo)->! {
loop{}
}
and add this to cargo.toml[dependencies]
libc="*"
[profile.dev]
panic="abort"
opt-level=3
and add this in .cargo/config.toml[build]
rustflags = ["-C", "link-args=-lc"]
after stripping the binary it is 16K
After removing the rust standard library you can check the binary if it contains the panic function. If it does that means the program may crash. If it doesn't then it cannot crash. (except in unsafe code). This feature can make rust code safe, but almost no one uses it.
Embed Notice
HTML Code
Corresponding Notice
- Embed this notice
reimu@mk.fumo.pictures's status on Sunday, 16-Mar-2025 21:51:22 JST reimu