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

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

问题描述

当我尝试运行仅具有执行访问权限的脚本时,出现以下错误:

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

uname: symbol lookup error: /home/dumindara/random/sotest/a.out: undefined symbol: 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进行链接,以及在运行unamels时直接或间接引入了哪些库.

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天全站免登陆