I met some trouble when using LD_PRELOAD to load my so.
The steps are as following:
libtest.c:
void fun() { return }gcc -o libtest.so libtest.c -fPIC --shared
export LD_PRELOAD=
pwd/libtest.somain.c
extern void fun(); void main() { fun() }gcc -o main -L. main.c -ltest
Then
ldd mainldd main linux-vdso.so.1=>(0x00007ffff7ffd000) /home/shiyanlou/Code/libtest.so(0x00007ffff7df9000) libtest.so=>not found libc.so.6=>/lib/x86_64-linux-gnu/libc.so.6 (0x00007ffffa29000) /lib64/ld-linux-x86-64.so.2 (0x0000555555554000)- execute main
./mainit promotes: error while loading shared library:libtest.so. cannot open shared object file:No such file or directory.
I wonder that why it prompts that libtest.so cannot be found After I exported LD_PRELOAD variable. However, I also tried to use LD_PRELOAD to specify a different shared lib(not "libc.so") to inject malloc function, it works! Why LD_PRELOAD only works for the shared lib that was not used when linking???