-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
LC_DYLD_EXPORTS_TRIE
offset fixup
Fixes #29
- Loading branch information
1 parent
3172306
commit 2b3a33b
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extern "C" { | ||
fn dlsym(handle: isize, symbol: *const u8) -> usize; | ||
fn dlerror() -> *const u8; | ||
} | ||
|
||
#[no_mangle] | ||
pub extern "C" fn exported_sym() { | ||
println!("Hello from exported_sym"); | ||
} | ||
|
||
const RTLD_DEFAULT: isize = -2; | ||
|
||
fn main() { | ||
if unsafe { dlsym(RTLD_DEFAULT, "exported_sym\0".as_ptr()) } == 0 { | ||
let err = unsafe { dlerror() }; | ||
let err = unsafe { std::ffi::CStr::from_ptr(err as _) }; | ||
let err = err.to_str().unwrap(); | ||
eprintln!("Error: {}", err); | ||
panic!("Symbol not found"); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rustc --target x86_64-apple-darwin -Clink-arg="-Wl,-exported_symbol,_exported_sym" tests/rtld_default.rs | ||
cargo r -- ./tests/rtld_default tests/test.txt ./tests/out | ||
chmod +x ./tests/out | ||
./tests/out |