Skip to content

Instantly share code, notes, and snippets.

@nanpuyue
Last active April 30, 2022 13:35
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 nanpuyue/a321af0e553b6ac138a358990c91710d to your computer and use it in GitHub Desktop.
Save nanpuyue/a321af0e553b6ac138a358990c91710d to your computer and use it in GitHub Desktop.
executable-cdylib
/target
Cargo.lock
fn main() {
println!("cargo:rustc-cdylib-link-arg=-emain")
}
[package]
name = "executable-cdylib"
authors = ["南浦月 <nanpuyue@gmail.com>"]
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
path = "lib.rs"
crate-type = ["cdylib"]
#![allow(unused)]
use std::io::{stdout, Write};
use std::process::exit;
#[no_mangle]
#[link_section = ".interp"]
static INTERP: [u8; 26] = *b"/lib/ld-linux-x86-64.so.2\0";
#[no_mangle]
unsafe extern "C" fn main() {
let _ = stdout().write_all(&*b"Hello World!\n");
// stdout().write_all(&*b"Hello World!\n").unwrap(); // Segmentation fault with debug build
// println!("Hello World!"); // Segmentation fault with debug/release build
exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment