使用$ ORIGIN指定ELF二进制文件中的解释器不起作用

时间:2018-01-25 22:17:04

标签: linux linker elf

我正在使用patchelf修改rpath和已编译二进制文件的解释器。对patchelf的调用看起来像这样:

readelf -l ./grep | grep interpreter

这些设置正确,通过运行[Requesting program interpreter: $ORIGIN/lib/ld-linux-x86-64.so.2] 验证,输出:

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

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

$ORIGIN

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

我想知道我在这里使用const DATA = require("../resources/data.json"); const Request = require("request"); class Net { constructor(){} _handleResponses(e, r, b) { console.log("--------------------------------------------------------------"); if(r.statusCode == 404) { console.log("\x1b[31m"+`[RESPONSE](Status ${r.statusCode})`, "\x1b[0m"); console.log("\x1b[31m"+`Server: ${service.server}`, "\x1b[0m"); console.log("\x1b[31m"+`Service: ${service.service}`, "\x1b[0m"); console.log("\x1b[31m"+`Body: ${b}`, "\x1b[0m"); } else { console.log(`[RESPONSE](Status ${r.statusCode})`); console.log(`Server: ${service.server}`); console.log(`Service: ${service.service}`); console.log(`Body: ${b}`); } } pollServices() { for(let service of DATA) { Request(service.url, this._handleResponses); } } } module.exports = Net; 的方式是否有些不正确,或者这可能在系统级别被禁用了?

1 个答案:

答案 0 :(得分:5)

  

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

这是按预期工作的。

动态链接器解释(扩展)$ORIGIN和其他特殊标记。

Linux内核

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

没有办法让解释器本身成为有效路径以外的任何东西。

根据您实际试图实现的目标,rtldi可能就是答案。