Last active
January 15, 2021 10:19
-
-
Save 0atman/22986cf29fee0772b9ec4af81d92632a to your computer and use it in GitHub Desktop.
Simple C programming bootstrap file in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This creates a 14k executable, linked to libc