Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 -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;
}
like image 274
MetallicPriest Avatar asked Dec 12 '11 11:12

MetallicPriest


People also ask

What is ETC Ld so preload?

etc/ld.so.preload File containing a whitespace-separated list of ELF shared objects to be loaded before the program.

What is Ld_preload in Linux?

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 .


1 Answers

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
like image 63
codaddict Avatar answered Oct 18 '22 06:10

codaddict