Skip to content

Instantly share code, notes, and snippets.

@nbdd0121

nbdd0121/a.rs Secret

Last active March 7, 2024 17:52
Show Gist options
  • Save nbdd0121/d4bf7dd7f9b6d6b50fa18b1092f45a3c to your computer and use it in GitHub Desktop.
Save nbdd0121/d4bf7dd7f9b6d6b50fa18b1092f45a3c to your computer and use it in GitHub Desktop.
extern crate b;
extern "C" {
fn foo() -> i32;
}
#[no_mangle]
pub extern "C" fn main() -> i32 {
unsafe { foo() + b::bar() }
}
extern "C" {
fn foo() -> i32;
}
pub fn bar() -> i32 {
unsafe { foo() }
}
extern inline int foo() {
return 1;
}
#!/usr/bin/env bash
clang -S helper.c -emit-llvm -o helper.ll -O2
sed -i 's/^define dso_local/define linkonce_odr dso_local/g' helper.ll
llvm-as helper.ll -o helper.bc
rustc +stage1 --crate-type=lib --emit=llvm-bc --emit=metadata b.rs -C opt-level=2 -L .
rustc +stage1 --crate-type=lib --emit=llvm-bc --emit=metadata a.rs -C opt-level=2 -L .
llvm-link b.bc helper.bc -o b.m.bc
clang -c b.m.bc -o b.o -O2
llvm-link a.bc helper.bc -o a.m.bc
clang -c a.m.bc -o a.o -O2
clang a.o b.o -o final.o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment