Last active
April 30, 2022 13:35
-
-
Save nanpuyue/a321af0e553b6ac138a358990c91710d to your computer and use it in GitHub Desktop.
executable-cdylib
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
/target | |
Cargo.lock |
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
fn main() { | |
println!("cargo:rustc-cdylib-link-arg=-emain") | |
} |
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
[package] | |
name = "executable-cdylib" | |
authors = ["南浦月 <[email protected]>"] | |
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"] |
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
#![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