Skip to content

Instantly share code, notes, and snippets.

@0atman
Last active January 15, 2021 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0atman/22986cf29fee0772b9ec4af81d92632a to your computer and use it in GitHub Desktop.
Save 0atman/22986cf29fee0772b9ec4af81d92632a to your computer and use it in GitHub Desktop.
Simple C programming bootstrap file in Rust
#![feature(start, libc, lang_items)]
#![no_std]
#![no_main]
#![feature(rustc_private)]
extern crate libc;
extern { // A list of imported C functions
pub fn printf(format: *const u8, ...) -> i32;
}
#[lang = "eh_personality"]
extern fn eh_personality() {}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
// Code starts below
#[no_mangle]
pub extern fn main(_nargs: i32, _args: *const *const u8) -> i32 {
unsafe {
printf(b"Hello, World!\n" as *const u8);
}
return 0
}
@0atman
Copy link
Author

0atman commented Jan 15, 2021

This creates a 14k executable, linked to libc

@0atman
Copy link
Author

0atman commented Jan 15, 2021

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