为子进程定制 ld-linux.so

发布于 2025-01-16 18:40:55 字数 623 浏览 3 评论 0原文

我正在运行一个带有一组自定义库的程序,如下所示:

/path/to/my/ld-linux-x86-64.so.2 --library-path /path/to/my/libs /path/to/my/executable

这对于我尝试运行的大多数程序都非常有效,但它似乎不适用于生成子进程的程序。我很确定子进程是用标准 glibc execve 生成的。子进程失败并出现库错误,这似乎是由于子进程未正确执行而引起的。该程序将 LD_LIBRARY_PATH 设置为包含 distroless Docker 容器中除 libc 之外的所有库的目录,因此我非常确定所有库都是正确的。

我还尝试使用设置 LD_LIBRARY_PATH 并使用 ld-linux-x86-64.so.2 调用,但这也不起作用。

我认为问题在于子进程正在恢复到系统/lib64/ld-linux-x86-64.so.2

对于上下文,我有一个二进制文件(以及第二个二进制文件,第一个二进制文件作为子进程调用),我没有构建它,我想在安装了不同动态库集的各种系统上运行。使用 LD_LIBRARY_PATH 并提供除 libc 之外的所有库适用于大多数环境,但安装了非常旧的 glibc 的环境除外。

I am running a program with a set of custom libraries as follows:

/path/to/my/ld-linux-x86-64.so.2 --library-path /path/to/my/libs /path/to/my/executable

This works great for most of the programs I am trying to run, but it doesn't seem to work for one which spawns subprocesses. I'm pretty sure the subprocesses are being spawned with standard glibc execve. The subprocess is failing with a library error which appears to be caused by it not being executed properly. The program works with LD_LIBRARY_PATH set to the a directory containing all of the libraries except libc in a distroless Docker container, so I am pretty sure that I have all of the libraries correct.

I also tried using both setting LD_LIBRARY_PATH and invoking with ld-linux-x86-64.so.2, but that doesn't work either.

I think the problem is that the subprocess is reverting to the system /lib64/ld-linux-x86-64.so.2.

For context, I have a binary (and a second binary which the first invokes as a subprocess) that I didn't build that I want to run on various systems with different sets of dynamic libraries installed. Using LD_LIBRARY_PATH and providing all libraries except libc works for most environments, except for one with a really old glibc installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆で 2025-01-23 18:40:55

我认为问题在于子进程正在恢复到系统/lib64/ld-linux-x86-64.so.2。

如果 execve 参数是 /path/to/subprocesssubprocess,这就是人们应该期望发生的情况。

如果您希望子进程使用显式加载程序调用 /path/to/my/ld-linux-x86-64.so.2 --library-path /path/to/my/libs /path/to/subprocess,那么您必须安排execve参数完全如此

这就是为什么使用 patchelf这个答案 中的其他解决方案通常是更好的方法。

I think the problem is that the subprocess is reverting to the system /lib64/ld-linux-x86-64.so.2.

That is what one should expect to happen if the execve argument is /path/to/subprocess or subprocess.

If you want the subprocess to use explicit loader invocation /path/to/my/ld-linux-x86-64.so.2 --library-path /path/to/my/libs /path/to/subprocess, then you must arrange for execve arguments to be exactly that.

This is why using patchelf or other solutions from this answer is generally a better approach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文