ELF共享库:重定位偏移超出范围
有一个软件包 elfutils
,其中包含一个名为 eu-elflint
的程序,用于检查 ELF 二进制文件(就像 C 的 lint
- 因此得名) 。
只是出于好奇,我用这个工具检查了我们自己的共享库,它发现了很多问题,例如:
eu-elflint libUtils.so
section [ 2] '.dynsym': _DYNAMIC symbol size 0 does not match dynamic segment size 248
section [ 2] '.dynsym': _GLOBAL_OFFSET_TABLE_ symbol size 0 does not match .got.plt section size 3076
section [ 8] '.rel.plt': relocation 0: offset out of bounds
section [ 8] '.rel.plt': relocation 1: offset out of bounds
...
section [ 8] '.rel.plt': relocation 765: offset out of bounds
作为交叉检查,我从下面的源代码构建了一个非常简单的共享库
int foo(int a) {
return a + 1;
}
// gcc -shared -fPIC -o libfoo.so foo.c
并再次尝试......
eu-elflint libfoo.so
section [ 9] '.rel.plt': relocation 0: offset out of bounds
section [ 9] '.rel.plt': relocation 1: offset out of bounds
section [23] '.comment' has wrong flags: expected none, is MERGE|STRINGS
section [25] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol size 0 does not match .got.plt section size 20
section [25] '.symtab': _DYNAMIC symbol size 0 does not match dynamic segment size 200
正如你所看到的这个简单的例子也说明了很多问题。
顺便说一句:我使用的是带有 gcc v4.4.1 的 Ubuntu-Karmic-32bit
顺便说一句:...同样的情况发生在带有 gcc v4.2.4 的 Debian-Lenny-64bit 上,
这是我应该担心的事情吗?
There is a software package elfutils
which includes a program called eu-elflint
for checking ELF binaries (just as lint
for C - hence the name).
Just for curiosity I have checked our own shared libraries with this tool and it found a lot of issues, e.g.:
eu-elflint libUtils.so
section [ 2] '.dynsym': _DYNAMIC symbol size 0 does not match dynamic segment size 248
section [ 2] '.dynsym': _GLOBAL_OFFSET_TABLE_ symbol size 0 does not match .got.plt section size 3076
section [ 8] '.rel.plt': relocation 0: offset out of bounds
section [ 8] '.rel.plt': relocation 1: offset out of bounds
...
section [ 8] '.rel.plt': relocation 765: offset out of bounds
As a crosscheck I have build a very trivial shared library from the source code below
int foo(int a) {
return a + 1;
}
// gcc -shared -fPIC -o libfoo.so foo.c
And tried again ...
eu-elflint libfoo.so
section [ 9] '.rel.plt': relocation 0: offset out of bounds
section [ 9] '.rel.plt': relocation 1: offset out of bounds
section [23] '.comment' has wrong flags: expected none, is MERGE|STRINGS
section [25] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol size 0 does not match .got.plt section size 20
section [25] '.symtab': _DYNAMIC symbol size 0 does not match dynamic segment size 200
As you can see even the trivial example also shows a lot of issues.
BTW: I am on Ubuntu-Karmic-32bit with gcc v4.4.1
BTW: ... the same happens on Debian-Lenny-64bit with gcc v4.2.4
Is this something I should be concerned about?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速回答:“这是我应该关心的事情吗?” 不。
更长的答案:elflint 不仅检查 ABI 标准,还检查一些 ELF 约定。 ABI 和 ELF 约定都随着时间的推移而变化:ABI 被扩展,并且必须保持向后兼容,并且 ELF 约定确实随着时间的推移而发展(主要是为了获得新功能)。因此,elflint 的期望必须与您的汇编器/链接器(在本例中为 GNU binutils)生成的内容保持同步。您可以找到许多关于 GNU binutils 中引入的新 ELF 扩展的 elflint 报告,而 elflint 稍后才会捕获这些扩展。因此,您的 elflint 版本很可能对于您安装的 binutils 来说太旧了。由于 elflint 的使用并不多,因此 Linux 发行版不能很好地保持这两者的同步,我并不感到惊讶。
Quick answer: "Is this something I should be concerned about?" No.
Longer answer: elflint checks not only ABI standards, but also some ELF conventions. Both ABIs and ELF conventions change over time: ABIs are extended, and have to remain backward compatible, and ELF conventions do evolve over time (to get new features, mainly). As a consequence, elflint's expectations have to be kept in sync with what your assembler/linker (the GNU binutils in this case) produce. You can find lots of reports to elflint about new ELF extensions introduced in GNU binutils, and for which elflint only catches later on. Thus, it's most probable that you have a version of elflint that is too old for your installed binutils. As elflint is not so much used, it wouldn't surprise me that a linux distro doesn't keep those two in sync so well.