associated functions don't seem to be working as intended for cdylib, but works for dylib #76211
Labels
A-FFI
Area: Foreign function interface (FFI)
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
The suspicion on the RUST forum is that assocaited functions are not working correctly for cdylib
Associated RUST forum thread
https://users.rust-lang.org/t/ld-preload-works-as-dylib-and-doesnt-as-cdylib-which-is-the-right-choice/48174
I am building an LD_PRELOAD library.
It was recommended in the rust forum that I use cdylib as crate type to build the Rust LD_PRELOAD shared library I am working with. I was using dylib before that.
My reading of other threads i this group also backsup his recommendation
https://users.rust-lang.org/t/what-is-the-difference-between-dylib-and-cdylib/28847
Interestingly enough dylib was working for me. I then switched cdylib and the LD_PRELOAD intercept portion stopped working. Though the .so still gets exectued as shown below.
Here is an example rust shared library code I used for testing. It intercepts readlink to print some debug print messages and continues to the original readlink.
My Cargo.toml looks like this
And this works. I see the constructor executing, and my_readlink which is my itnercept function and ls -al /tmp/link works and shows the symlink as expected, so the original readlink was executed as well. So all is well here
I then changed
crate_type = ["dylib"]
to
crate_type = ["cdylib"]
And I see this. Only the constructor of libreadlink.so gets executed. But none of the interception happens.
Is cdylib the right choice? and why doesnt my interception not work as the recommended cdylib but works as a dylib ?
Considering dylib is supposed to be smaller and is working. Can I continue as dylib? Or should I be worried about any other pitfalls for dylibs exposing C externs for calls from other C programs?
<code>
I expected to see this happen: explanation
Instead, this happened: explanation
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: