为 LD_PRELOAD 设置我的库会使某些进程产生加载程序错误 [英] Setting my lib for LD_PRELOAD makes some processes produce loader errors

查看:23
本文介绍了为 LD_PRELOAD 设置我的库会使某些进程产生加载程序错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行我只有执行权限的脚本时出现以下错误:

I get the following error when I try to run a script I have only execution access for:

uname:符号查找错误:/home/dumindara/random/sotest/a.out:未定义符号:dlsym

这是在我将 LD_PRELOAD 环境变量设置为 /home/dumindara/random/sotest/a.out 之后.

This is after I have set LD_PRELOAD environment variable to /home/dumindara/random/sotest/a.out.

a.out有一个测试malloc函数,内部调用dlsym.

a.out has a test malloc function, and calls dlsym internally.

我在运行 ls 时没有遇到这个问题.大多数进程确实给出了这个错误.为什么会发生这种情况,我该怎么做才能让它发挥作用?

I don't get this problem when running ls. Most processes do give this error. Why does this happen and what can I do to make it work?

推荐答案

我假设您的 a.out 文件是共享对象而不是可执行文件,然后继续...

I assume that your a.out file is a shared object and not a executable and move on...

dlsym() 是 libdl 库中的一个函数,它通常驻留在现代 Linux 系统上的 libdl.so.2 共享对象中.

dlsym() is a function from the libdl library, which usually resides in the libdl.so.2 shared object on modern Linux systems.

我会猜测您的 a.out 共享对象未链接到 libdl.这意味着,当您预加载像 uname 这样的简单二进制文件时,它不会拉入很多其他库,libdl.so.2 可能不会被拉入,并且您会收到未定义符号错误.

I'll hazzard a guess that your a.out shared object is not linked to libdl. That means that when you preload in a simple binary like uname that does not pull in a lot of other libraries, libdl.so.2 may not be pulled in and you get an undefined symbol error.

另一方面,如果您将其预加载到链接到并最终拉入 libdl.so.2 的二进制文件中,则您的共享对象可以正常工作.

If, on the other hand, you preload it to a binary that is linked to and finally pulls in libdl.so.2, your shared object works fine.

我会用 ldd 检查您自己的共享对象是否按应有的方式与 libdl 链接,以及当 uname 和 <代码>ls运行.

I'd check with ldd if your own shared object is linked against libdl as it should, and also what libraries are directly or indirectly pulled in when uname and ls run.

我刚刚确认了这一点.解决此错误的方法是将您的共享对象与 libdl 链接.将 -ldl 添加到它的 LDFLAGS 应该可以解决问题.

I just confirmed this. The way to fix this error is to link your shared object against libdl. Adding -ldl to its LDFLAGS should do the trick.

这篇关于为 LD_PRELOAD 设置我的库会使某些进程产生加载程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆