简体   繁体   English

如何在符号表中添加共享库版本信息

[英]How to add shared library version info in the symbol table

I wrote a small simple test program that uses libz. 我编写了一个使用libz的小型简单测试程序。 I compiled it using 我用它编译

$gcc -o test test.c -lz

To see how libz functions are added to my symbol table I ran the following command 要查看如何将libz函数添加到我的符号表中,我运行了以下命令

$ readelf -s test | grep inflate

Here is the output 这是输出

 1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND inflateEnd
 8: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND inflate
13: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND inflateInit_
51: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND inflateEnd
62: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND inflate
73: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND inflateInit_

libz that I am using has .gnu.version_d section defined as follows 我正在使用的libz具有.gnu.version_d部分,定义如下

Version definition section '.gnu.version_d' contains 7 entries:
Addr: 0x0000003175e014c0  Offset: 0x0014c0  Link: 4 (.dynstr)
000000: Rev: 1  Flags: BASE   Index: 1  Cnt: 1  Name: libz.so.1
0x001c: Rev: 1  Flags: none  Index: 2  Cnt: 1  Name: ZLIB_1.2.0
0x0038: Rev: 1  Flags: none  Index: 3  Cnt: 2  Name: ZLIB_1.2.0.2
0x0054: Parent 1: ZLIB_1.2.0
0x005c: Rev: 1  Flags: none  Index: 4  Cnt: 2  Name: ZLIB_1.2.0.8
0x0078: Parent 1: ZLIB_1.2.0.2
0x0080: Rev: 1  Flags: none  Index: 5  Cnt: 2  Name: ZLIB_1.2.2
0x009c: Parent 1: ZLIB_1.2.0.8
0x00a4: Rev: 1  Flags: none  Index: 6  Cnt: 2  Name: ZLIB_1.2.2.3
0x00c0: Parent 1: ZLIB_1.2.2
0x00c8: Rev: 1  Flags: none  Index: 7  Cnt: 2  Name: ZLIB_1.2.2.4
0x00e4: Parent 1: ZLIB_1.2.2.3

So why is libz version not part of libz function symbols in my symbol table. 那么,为什么我的符号表中的libz版本不是libz函数符号的一部分。 I expect to see something like - 我希望看到类似-

1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND inflateEnd@@ZLIB_1.2.0
...

Also .gnu.version_r section of my binary does not list libz version as a requirement. 另外,我的二进制文件的.gnu.version_r部分未列出libz版本。 How can I add libz version dependency here? 如何在此处添加libz版本依赖性?

$readelf -V test

...
Version needs section '.gnu.version_r' contains 1 entries:
Addr: 0x0000000000400618  Offset: 0x000618  Link: 6 (.dynstr)
000000: Version: 1  File: libc.so.6  Cnt: 1
 0x0010:   Name: GLIBC_2.2.5  Flags: none  Version: 2

Just because your libz contains versioning information does not mean that every symbol within is versioned. 仅仅因为您的libz包含版本信息,并不意味着其中的每个符号都已被版本化。 In my libz (version 1.2.3 (yes, really)), some of the external symbols are versioned and some are not, as I can determine via readelf . 在我的libz(版本1.2.3(是,确实)中)中,一些外部符号已版本化,而有些则没有,我可以通过readelf确定。 Specifically, all of the symbols you asked about are defined by my DSO, but none of them are versioned. 具体来说,您要查询的所有符号都是由我的DSO定义的,但是都没有版本化。

If you link against unversioned symbols, you should neither expect nor want the corresponding symbol references in your binary to be versioned. 如果链接未版本化的符号,则既不应期望也不希望对二进制文件中的相应符号引用进行版本控制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM