redhook
redhook copied to clipboard
Switch to cdylibs
This seems like the right thing to do (cf. Rust RFC 1510) but when I tried it it didn't export my hook function.
$ nm -D examples/readlinkspy/target/debug/libreadlinkspy.so
w __cxa_finalize
w __gmon_start__
w _ITM_deregisterTMCloneTable
w _ITM_registerTMCloneTable
w _Jv_RegisterClasses
00000000000009d0 T rust_eh_personality
U _Unwind_GetDataRelBase
U _Unwind_GetIPInfo
U _Unwind_GetLanguageSpecificData
U _Unwind_GetRegionStart
U _Unwind_GetTextRelBase
U _Unwind_SetGR
U _Unwind_SetIP
it didn't export my hook function
same, but it works with LD_PRELOAD
symbol count, as reported by nm 3139 dylib 68 cdylib
redhook + crate_type = ["cdylib"] requires rust-nightly
[lib]
crate_type = ["dylib"] # works with rust-stable and rust-nightly
# release binary size
# 2.7M rust-stable
# 5.2M rust-nightly
[lib]
crate_type = ["cdylib"] # requires rust-nightly. silently fails with rust-stable
# release binary size
# 450 KB rust-nightly
# 20 KB rust-stable (broken)
compile options for my project
[profile.release]
# https://arusahni.net/blog/2020/03/optimizing-rust-binary-size.html
# https://github.com/johnthagen/min-sized-rust
opt-level = "s" # optimize for binary size
lto = true
codegen-units = 1
panic = "abort" # disable backtraces on panic