首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用拼贴自带-设置解释器?

如何使用拼贴自带-设置解释器?
EN

Stack Overflow用户
提问于 2020-01-01 04:23:16
回答 1查看 5.6K关注 0票数 4

我想做以下几件事:

将简单test.c的libc从系统默认值(Debian 9.11,libc-2.24.so)更改为libc 2.27。

这是我的尝试:

代码语言:javascript
复制
user@pc:~/patchelf_test$ cat test.c 
#include <stdio.h>

int main(int argc, char **argv)
{
    printf("hello patchelf\n");

    return 0;
}
user@pc:~/patchelf_test$ gcc test.c -o test
user@pc:~/patchelf_test$ ./test
hello patchelf
user@pc:~/patchelf_test$ ldd test
    linux-vdso.so.1 (0x00007ffd9d1d8000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7ea0290000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7ea0831000)
user@pc:~/patchelf_test$ patchelf --set-interpreter ./libc6-amd64_2.27-3ubuntu1_i386.so test
warning: working around a Linux kernel bug by creating a hole of 2093056 bytes in ‘test’
user@pc:~/patchelf_test$ ldd test
    linux-vdso.so.1 (0x00007fff20b9a000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa46a35e000)
    ./libc6-amd64_2.27-3ubuntu1_i386.so => /lib64/ld-linux-x86-64.so.2 (0x00007fa46a900000)
user@pc:~/patchelf_test$ ./test
GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1) stable release version 2.27.
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 7.3.0.
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.
user@pc:~/patchelf_test$ 

这里的预期结果是它应该运行实际的程序。实际结果是,它运行链接器本身的

问题:,我需要如何修改我的命令来修复这个问题?

我还尝试使用libc6-AMD642.27-3ubuntu1_i386.ld代替.so:

代码语言:javascript
复制
user@pc:~/patchelf_test$ !gcc
gcc test.c -o test
user@pc:~/patchelf_test$ patchelf --set-interpreter ./libc6-amd64_2.27-3ubuntu1_i386.ld test
warning: working around a Linux kernel bug by creating a hole of 2093056 bytes in ‘test’
user@pc:~/patchelf_test$ ./test
Segmentation fault

我还尝试使用我的系统默认的libc,并使用它进行修补程序,仅仅是为了确定修补程序本身可以工作,但是我还是遇到了同样的问题--它执行链接器二进制本身,而不是测试二进制。

代码语言:javascript
复制
user@pc:~/patchelf_test$ !gcc
gcc test.c -o test
user@pc:~/patchelf_test$ patchelf --set-interpreter ./libc_default.so test
warning: working around a Linux kernel bug by creating a hole of 2093056 bytes in ‘test’
user@pc:~/patchelf_test$ ./test
GNU C Library (Debian GLIBC 2.24-11+deb9u4) stable release version 2.24, by Roland McGrath et al.
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 6.3.0 20170516.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.

绞刑:

代码语言:javascript
复制
$ strace ./test
execve("./test", ["./test"], [/* 44 vars */]) = 0
write(1, "GNU C Library (Debian GLIBC 2.24"..., 616GNU C Library (Debian GLIBC 2.24-11+deb9u4) stable release version 2.24, by Roland McGrath et al.
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 6.3.0 20170516.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.
) = 616
exit_group(0)                           = ?
+++ exited with 0 +++
EN

回答 1

Stack Overflow用户

发布于 2020-01-03 00:20:25

这个命令没有任何意义:

patchelf --set-interpreter ./libc6-amd64_2.27-3ubuntu1_i386.so test

libc.so.6ld-linux.so.2完全不同,您将PT_INTERP设置为(等效) libc.so.6

这个命令是“正确的”:

patchelf --set-interpreter ./libc6-amd64_2.27-3ubuntu1_i386.ld test

但是结果很可能是由于系统GLIBC是不同的版本而崩溃的。正如我所说的,hereld-linuxlibc.so.6必须完全匹配。

要使这一切正常工作,您应该去掉有趣的libc-amd64...命名约定,将2.27构建完全解压到例如./libc6-amd64_2.27/目录中,然后使用以下内容:

代码语言:javascript
复制
patchelf --set-interpreter ./libc6-amd64_2.27/lib64/ld-linux-x86-64.so.2 test
LD_LIBRARY_PATH=./libc6-amd64_2.27/lib64 ./test
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59549978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档