My project need to use LD_PRELOAD to change some native functions. But it seems LD_PRELOAD cannot work with both cargo run and cargo test. LD_RPELOAD only works on cargo, but does not work on the program/tests that cargo will execute.
Even export LD_PRELOAD=./mylib.so cannot work.
An example:
$ ./target/release/ld_preload_rs
Hello, world!
$ LD_PRELOAD=./mylib.so ./target/release/ld_preload_rs
Library is Loaded!
Hello, world!
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `target/debug/ld_preload_rs`
Hello, world!
$ LD_PRELOAD=./mylib.so cargo run
Library is Loaded!
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/ld_preload_rs`
Hello, world!
$ export LD_PRELOAD=./mylib.so
$ cargo run
Library is Loaded!
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/ld_preload_rs`
Hello, world!
No, it is just loaded for cargo, not for the program I'm running.
It should be loaded twice when using cargo, like:
$ cargo run
Library is Loaded!
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/ld_preload_rs`
Library is Loaded!
Hello, world!