Become a leader in the IoT community!
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
Join our community of embedded and IoT practitioners to contribute experience, learn new skills and collaborate with other developers with complementary skillsets.
I’m trying to use the LD_PRELOAD to inject my custom function in a program. I’ve compiled a shared library `getpid.so` having a modified getpid function that prints a message:
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
pid_t getpid(void)
{
printf("Initializing..n");
return syscall(SYS_getpid);
}
I’ve also compiled a program testpid.c that calls the regular getpid function:
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
printf( "pid = %d!n", getpid() );
return 0;
}
When I run the command:
LD_PRELOAD=./getpid.so ./testpid
I get the following error:
ERROR: ld.so: object 'getpid.so' from LD_PRELOAD cannot be preloaded: ignored
I’ve compiled both files with `gcc -Wall -fPIC -shared -o getpid.so getpid.c` and `gcc testpid -o testpid.c`
Can anyone help me understand why LD_PRELOAD is not working and how to fix the issue?
CONTRIBUTE TO THIS THREAD