When I try to use LD_PRELOAD as following,
LD_PRELOAD=getpid.so ./testpid
I get the following error...
ERROR: ld.so: object 'getpid.so' from LD_PRELOAD cannot be preloaded: ignored.
I compile getpid.so by using
gcc -Wall -fPIC -shared -o getpid.so getpid.c
and it contains the following code...
// getpid.c
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
pid_t getpid(void)
{
printf("Hello, world!\n");
return syscall(SYS_getpid);
}
tespid.c
constains code which uses getpid as shown below and which is compiled by doing
gcc testpid -o testpid.c
What can be the problem here? Why is LD_PRELOAD not working?
// testpid.c
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
printf( "pid = %d!\n", getpid() );
return 0;
}
etc/ld.so.preload File containing a whitespace-separated list of ELF shared objects to be loaded before the program.
LD_PRELOAD lists shared libraries with functions that override the standard set, just as /etc/ld. so. preload does. These are implemented by the loader /lib/ld-linux.so .
Looks like the loader is unable to find getpid.so
as you've not mentioned the path to the library.
Try:
LD_PRELOAD=/full/path/to/getpid.so ./testpid
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