使用$ ORIGIN在ELF二进制文件中指定解释器不起作用 [英] Using $ORIGIN to specify the interpreter in ELF binaries isn't working

查看:247
本文介绍了使用$ ORIGIN在ELF二进制文件中指定解释器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 patchelf 修改rpath和已编译二进制文件的解释器.对patchelf的调用如下所示:

I'm using patchelf to modify rpath and the interpreter for already compiled binaries. The calls to patchelf look something like this:

patchelf --set-interpreter "\$ORIGIN/lib/ld-linux-x86-64.so.2" --set-rpath "\$ORIGIN/lib" ./grep

这些已正确设置,通过运行readelf -l ./grep | grep interpreter进行验证,该输出将输出:

These are being set correctly, as verified by running readelf -l ./grep | grep interpreter, which outputs:

[Requesting program interpreter: $ORIGIN/lib/ld-linux-x86-64.so.2]

但是,当我尝试运行可执行文件时,出现以下错误:

When I try to run the executable, however, I get the following error:

-bash: ./grep: No such file or directory

这似乎表明链接器存在问题.如果我指定了绝对路径而不是使用$ORIGIN,那么它似乎可以正常工作.

This seems to indicate that there's an issue with the linker. If I specify an absolute path instead of using $ORIGIN then it seems to work fine.

我想知道我在这里使用$ORIGIN的方式是否有问题,或者这是否在系统级别已被禁用?

I'm wondering if there's something incorrect about how I'm using $ORIGIN here, or if this is perhaps something that has perhaps been disabled on a system level?

推荐答案

如果我指定了绝对路径而不是使用$ ORIGIN,那么它似乎可以正常工作.

If I specify an absolute path instead of using $ORIGIN then it seems to work fine.

这按预期工作.

它是动态链接程序,用于解释(扩展)$ORIGIN和其他特殊标记.

It is the dynamic linker that interprets (expands) $ORIGIN and other special tokens.

Linux内核没有.

它是内核,它读取主要可执行文件的PT_INTERP段,并且(如果存在)加载并调用解释器(动态链接器).将解释器设置为不存在的路径(例如$ORIGIN/lib/ld-linux-x86-64.so.2)时,会从内核execve系统调用中获得ENOENT.

And it is the kernel that reads PT_INTERP segment of the main executable and (if present) loads and invokes the interpreter (the dynamic linker). When you set interpreter to non-existant path (such as $ORIGIN/lib/ld-linux-x86-64.so.2), you get ENOENT from the kernel execve system call.

除了有效路径外,没有其他方法可以使解释器本身成为其他任何东西.

There is no way to make interpreter itself be anything other than valid path.

根据您实际想要达到的目标, rtldi 可能就是答案.

Depending on what you are actually trying to achieve, rtldi may be the answer.

这篇关于使用$ ORIGIN在ELF二进制文件中指定解释器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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