I know how to override one library with LD_PRELOAD, for example, as follows.
LD_PRELOAD=./getpid.so ./testpid
Now my question is how to override multiple files. Say I want to override both getpid and getid, how would I specify that?
The LD_PRELOAD trick exploits functionality provided by the dynamic linker on Unix systems that allows you to tell the linker to bind symbols provided by a certain shared library before other libraries.
LD_PRELOAD is an optional environmental variable containing one or more paths to shared libraries, or shared objects, that the loader will load before any other shared library including the C runtime library (libc.so) This is called preloading a library.
LD_PRELOAD (not LD_PRELOAD_PATH ) is a list of specific libraries (files) to be loaded before any other libraries, whether the program wants it or not. LD_LIBRARY_PATH is a list of directories to search when loading libraries that would have been loaded anyway.
LD_PRELOAD is an environment variable (part of the "environment" defined by the C library and Unix conventions). That specific variable tells the dynamic linker how to behave. It is probably not set to anything by default.
According to the ld.so
manpage, it is a space separated list. So:
LD_PRELOAD="path1 path2"
ought to work.
One option is to have the overridden version of both getpid
and getid
in a single .so
which you give to LD_PRELOAD
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With