clinuxdynamicx86-64

ERROR: ld.so: object 'getpid.so' from LD_PRELOAD cannot be preloaded: ignored


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.c -o testpid

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;
}

Solution

  • 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