在Linux中存根用于标准库。为什么需要存根? [英] In Linux stubs are used for standard libraries. Why are stubs required?

查看:130
本文介绍了在Linux中存根用于标准库。为什么需要存根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux中,为什么是标准库所需的存根?

In Linux, why are stubs required for standard libraries?

推荐答案

需要存根,以确保在各种Linux发行版的可执行文件的正确链接,而不建立目标文件。

stubs are required to ensure proper linking of an executable across various linux releases without building the object files.

例如:
让一个是我们正在建设的可执行文件:

For example: Let a be the executable we are building:

gcc -o a test.o test1.o test2.o -lz

在上述情况下执行一个具有( -lz 是libz.so链接)上libz.so的依赖。链接器解析libz.so使用LD_LIBRARY_PATH。

In the above case executable a has a dependency on the libz.so (-lz is to link with libz.so). The linker resolves libz.so using the LD_LIBRARY_PATH.

现在让我们看到了问题:

Now let us see the problem:

In RHEL4(Linux Zseries):
objdump -T /usr/lib64/libz.so.1 | grep stack_chk 

In RHEL5(Linux ZSeries);
objdump -T /usr/lib64/libz.so.1 | grep stack_chk

0000000000000000 DF UND 0000000000000031 GLIBC_2.4 __stack_chk_fail 

在RHEL5中,我们看到一个未定义符号在libz.so.
除非我们在上面的命令后,LZ的libc传递给连接器,这不能得到解决。

In RHEL5, we see an undefined symbol in the libz.so. Unless we pass libc to the linker after lz in the above command, this cannot be resolved.

存根:
如果我们产生libz.so存根,包装libz.so的所有符号中存根库和链路与存根库,而不是真正的图书馆,我们没有看到任何错误:

Stubs: If we generate the stub for libz.so, packing all the symbols of libz.so in to a stub library and link with the stub library instead of the real library, we don't see any errors:

修改链接线:

gcc -o a test.o test1.o test2.o -L/home/lib/stubs/ -lz

在/ home / lib中/存根目录中,我们通过名称libzstub.so有libz.so存根库。

In the /home/lib/stubs directory, we have a stub library for libz.so by name libzstub.so.

连接器具有更高优先级比LD_LIBRARY_PATH链接命令给出的路径。

Linker gives higher priority to the path given in the link command than LD_LIBRARY_PATH.

现在即使我们在RHEL5发布链接,链接器用于解析从/ home / lib中/存根目录中libz.so的符号。

Now even if we link in the RHEL5 release, the linker resolves the symbols for the libz.so from the /home/lib/stubs directory.

下面我用盒子的配置细节。

Here the configuration details of the boxes i have used.

装载机需要在运行时加载的coresponding功能的照顾。

Loader takes care of loading the coresponding function at runtime.

RHEL5:

libcmpiutil-0.4-2.el5
glibc-utils-2.5-42
libc-client-2004g-2.2.1
libcap-1.10-26
libcap-1.10-26
libchewing-devel-0.3.0-8.el5
libchewing-0.3.0-8.el5
libcxgb3-1.2.3-1.el5
libcap-devel-1.10-26
glibc-common-2.5-42
libcxgb3-static-1.2.3-1.el5
libcroco-devel-0.6.1-2.1
compat-glibc-headers-2.3.4-2.26
libcroco-0.6.1-2.1
compat-libcom_err-1.0-7
libcmpiutil-devel-0.4-2.el5
compat-glibc-2.3.4-2.26
glibc-headers-2.5-42
glibc-devel-2.5-42
libcap-devel-1.10-26
libc-client-2004g-2.2.1
libcmpiutil-0.4-2.el5
libcroco-0.6.1-2.1
libc-client-devel-2004g-2.2.1
glibc-2.5-42
libchewing-devel-0.3.0-8.el5
libcroco-devel-0.6.1-2.1
compat-libcom_err-1.0-7
libc-client-devel-2004g-2.2.1
libchewing-0.3.0-8.el5
libcxgb3-1.2.3-1.el5
libcmpiutil-devel-0.4-2.el5
glibc-2.5-42
glibc-devel-2.5-42
compat-glibc-2.3.4-2.26

RHEL4:

rpm -qa | grep libc
glibc-2.3.4-2.41
libcxgb3-1.1.4-1.el4
libc-client-2002e-14
libcroco-0.6.0-4
libcap-devel-1.10-20
glibc-kernheaders-2.4-9.1.103.EL
compat-libcom_err-1.0-5
glibc-devel-2.3.4-2.41
compat-glibc-2.3.2-95.30
compat-libcom_err-1.0-5
glibc-common-2.3.4-2.41
libcroco-devel-0.6.0-4
libcxgb3-1.1.4-1.el4
libc-client-2002e-14
glibc-utils-2.3.4-2.41
libcap-1.10-20
glibc-headers-2.3.4-2.41
glibc-profile-2.3.4-2.41
libcxgb3-static-1.1.4-1.el4
glibc-devel-2.3.4-2.41
compat-glibc-2.3.2-95.30

这篇关于在Linux中存根用于标准库。为什么需要存根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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