为子进程定制 ld-linux.so
我正在运行一个带有一组自定义库的程序,如下所示:
/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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
execve
参数是/path/to/subprocess
或subprocess
,这就是人们应该期望发生的情况。如果您希望子进程使用显式加载程序调用
/path/to/my/ld-linux-x86-64.so.2 --library-path /path/to/my/libs /path/to/subprocess
,那么您必须安排execve
参数完全如此。这就是为什么使用
patchelf
或 这个答案 中的其他解决方案通常是更好的方法。That is what one should expect to happen if the
execve
argument is/path/to/subprocess
orsubprocess
.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 forexecve
arguments to be exactly that.This is why using
patchelf
or other solutions from this answer is generally a better approach.