Setting my lib for LD_PRELOAD makes some processes produce loader errors

nakiya picture nakiya · Dec 8, 2010 · Viewed 11.1k times · Source

I get the following error when I try to run a script I have only execution access for:

uname: symbol lookup error: /home/dumindara/random/sotest/a.out: undefined symbol: dlsym

This is after I have set LD_PRELOAD environment variable to /home/dumindara/random/sotest/a.out.

a.out has a test malloc function, and calls dlsym internally.

I don't get this problem when running ls. Most processes do give this error. Why does this happen and what can I do to make it work?

Answer

kraju picture kraju · Oct 24, 2012

I am unable to comment to the accepted answer, however it is worth to mention here that one can encounter issue of not having libdl.so.2 linked properly when -ldl is used in front of compile command (assuming that linking and compilation is executed by the same command; this is possible since LD_PRELOAD libs are usually based on one source file).

So call gcc with -ldl at the end:

gcc -shared -fPIC fakeuname.c -o libfakeuname.so -ldl

In my case, having -ldl at front resulted in error same as in question:

uname: symbol lookup error: ./libfakehostname.so: undefined symbol: dlsym