链接旧版本的 libc 以提供更大的应用程序覆盖率 [英] Linking against an old version of libc to provide greater application coverage
问题描述
Linux 二进制文件通常动态链接到核心系统库 (libc).这使得二进制文件的内存占用非常小,但依赖于最新库的二进制文件不会在旧系统上运行.相反,链接到旧库的二进制文件将在最新系统上愉快地运行.
Linux binaries are usually dynamically linked to the core system library (libc). This keeps the memory footprint of the binary quite small but binaries which are dependent on the latest libraries will not run on older systems. Conversely, binaries linked to older libraries will run happily on the latest systems.
因此,为了确保我们的应用程序在分发期间具有良好的覆盖率,我们需要找出我们可以支持的最旧的 libc 并将我们的二进制文件链接到它.
Therefore, in order to ensure our application has good coverage during distribution we need to figure out the oldest libc we can support and link our binary against that.
我们应该如何确定可以链接到的最旧版本的 libc?
How should we determine the oldest version of libc we can link to?
推荐答案
找出可执行文件中的哪些符号正在创建对不想要的 glibc 版本的依赖.
Work out which symbols in your executable are creating the dependency on the undesired version of glibc.
$ objdump -p myprog
...
Version References:
required from libc.so.6:
0x09691972 0x00 05 GLIBC_2.3
0x09691a75 0x00 03 GLIBC_2.2.5
$ objdump -T myprog | fgrep GLIBC_2.3
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.3 realpath
查看依赖库中是否有旧版本中可以链接的符号:
Look within the depended-upon library to see if there are any symbols in older versions that you can link against:
$ objdump -T /lib/libc.so.6 | grep -w realpath
0000000000105d90 g DF .text 0000000000000021 (GLIBC_2.2.5) realpath
000000000003e7b0 g DF .text 00000000000004bf GLIBC_2.3 realpath
我们很幸运!
从代码中的 GLIBC_2.2.5
请求版本:
Request the version from GLIBC_2.2.5
in your code:
#include <limits.h>
#include <stdlib.h>
__asm__(".symver realpath,realpath@GLIBC_2.2.5");
int main () {
realpath ("foo", "bar");
}
发现不再需要 GLIBC_2.3:
Observe that GLIBC_2.3 is no longer needed:
$ objdump -p myprog
...
Version References:
required from libc.so.6:
0x09691a75 0x00 02 GLIBC_2.2.5
$ objdump -T myprog | grep realpath
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 realpath
有关详细信息,请参阅 http://web.archive.org/web/20160107032111/http://www.trevorpounds.com/blog/?p=103.
For further information, see http://web.archive.org/web/20160107032111/http://www.trevorpounds.com/blog/?p=103.
这篇关于链接旧版本的 libc 以提供更大的应用程序覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!