When I try to use LD_PRELOAD as following,
当我尝试使用LD_PRELOAD时,如下
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
我使用编译getpid.so
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
tespid.c使用getpid的constains代码,如下所示,并通过执行编译
gcc testpid -o testpid.c
What can be the problem here? Why is LD_PRELOAD not working?
这可能是什么问题?为什么LD_PRELOAD不起作用?
// 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;
}
1 个解决方案
#1
18
Looks like the loader is unable to find getpid.so
as you've not mentioned the path to the library.
看起来加载器无法找到getpid.so,因为您没有提到库的路径。
Try:
尝试:
LD_PRELOAD=/full/path/to/getpid.so ./testpid
#1
18
Looks like the loader is unable to find getpid.so
as you've not mentioned the path to the library.
看起来加载器无法找到getpid.so,因为您没有提到库的路径。
Try:
尝试:
LD_PRELOAD=/full/path/to/getpid.so ./testpid