Skip to content

Instantly share code, notes, and snippets.

@kekeimiku
Last active March 26, 2022 07:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kekeimiku/3ef73b6633b338d8d7e51aebeca3d5b7 to your computer and use it in GitHub Desktop.
Save kekeimiku/3ef73b6633b338d8d7e51aebeca3d5b7 to your computer and use it in GitHub Desktop.
The tiny rust-x64-helloworld experiment
#![no_std]
#![no_main]
use core::arch::asm;
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
#[no_mangle]
fn _start() {
let h: &str = "Hello, World!\n";
unsafe {
asm!(
"syscall",
in("rax") 1,
in("rdi") 1,
in("rsi") h.as_ptr() as u64,
in("rdx") h.len() as u64
);
//exit
asm!(
"syscall",
in("rax") 60
);
};
}
@kekeimiku
Copy link
Author

kekeimiku commented Apr 24, 2021

cargo build --release --target x86_64-unknown-linux-gnu
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "link-arg=-fuse-ld=lld", "-C", "link-arg=-nostdlib", "-C", "link-arg=-static", "-C", "link-arg=-Wl,--build-id=none"]
llvm-strip --strip-sections hello
ll rust-helloworld
327 byte     rust-helloworld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment