Skip to content

Instantly share code, notes, and snippets.

@tilpner
Created April 4, 2015 18:32
Show Gist options
  • Save tilpner/edc993a81ed8b0433087 to your computer and use it in GitHub Desktop.
Save tilpner/edc993a81ed8b0433087 to your computer and use it in GitHub Desktop.
#![no_std]
#![feature(no_std, libc, lang_items, start)]
#![no_main]
//! ```sh
//! # compile
//! rustc -C opt-level=3 -C no-stack-check standalone.rs
//! # strip
//! strip -sR .comment -R .gnu.hash -R .gnu.version -R .note.ABI-tag -R .note.gnu.build-id standalone
//! # check size
//! ls -lh standalone
//! # output: -rwxr-xr-x 1 till till 4.5K Apr 4 20:30 standalone*
//! ```
extern crate libc;
use libc::funcs::c95::stdio::puts;
const HELLO: &'static [u8] = b"Hello World!\x00";
#[no_mangle]
pub extern fn main(_argc: isize, _argv: *const *const u8) -> isize {
unsafe { puts(&HELLO[0] as *const u8 as *const i8); }
0
}
#[lang = "stack_exhausted"] extern fn stack_exhausted() {}
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment