Linux 错误:ld.so:无法预加载来自 LD_PRELOAD 的对象“getpid.so”:忽略

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8473941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 03:36:13  来源:igfitidea点击:

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

clinuxdynamicx86-64

提问by MetallicPriest

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.cconstains code which uses getpid as shown below and which is compiled by doing

tespid.c包含使用 getpid 的代码,如下所示,并通过执行编译

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

采纳答案by codaddict

Looks like the loader is unable to find getpid.soas you've not mentioned the path to the library.

看起来加载器无法找到,getpid.so因为您没有提到库的路径。

Try:

尝试:

LD_PRELOAD=/full/path/to/getpid.so ./testpid