Using $ORIGIN to specify the interpreter in ELF binaries isn't working

亡梦爱人 提交于 2019-12-14 01:11:12

问题


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

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

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.

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?


回答1:


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

This is working as intended.

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

The Linux kernel doesn't.

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.

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



来源:https://stackoverflow.com/questions/48452793/using-origin-to-specify-the-interpreter-in-elf-binaries-isnt-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!