Skip to content

Commit

Permalink
Fix LC_DYLD_EXPORTS_TRIE offset fixup
Browse files Browse the repository at this point in the history
Fixes #29
  • Loading branch information
littledivy committed Sep 30, 2024
1 parent 3172306 commit 2b3a33b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ const LC_DYLD_INFO: u32 = 0x22;
const LC_DYLD_INFO_ONLY: u32 = 0x80000022;
const LC_DYLIB_CODE_SIGN_DRS: u32 = 0x2b;
const LC_LINKER_OPTIMIZATION_HINT: u32 = 0x2d;
const LC_DYLD_EXPORTS_TRIE: u32 = 0x8000001e;
const LC_DYLD_EXPORTS_TRIE: u32 = 0x80000033;
const LC_DYLD_CHAINED_FIXUPS: u32 = 0x80000034;

const CPU_TYPE_ARM_64: i32 = 0x0100000c;
Expand Down
21 changes: 21 additions & 0 deletions tests/rtld_default.rs
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");
}
}
4 changes: 4 additions & 0 deletions tests/test_rtld_default.sh
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

0 comments on commit 2b3a33b

Please sign in to comment.