为什么 objdump 不显示 .symtab 部分,而 readelf 却显示?

发布于 2024-09-04 16:41:41 字数 587 浏览 3 评论 0原文

我使用 gcc 编译一个简单的程序,如果我使用 objdump 看到节头,它不会显示节 .symtab。对于同一个 a.out 文件,readelf 显示以下部分:

[25] .symtab           SYMTAB          00000000 000ca4 000480 10     26  2c  4
[26] .strtab           STRTAB          00000000 001124 00025c 00      0   0  1

为什么?

在默认链接器脚本中,我没有找到 .symtab 部分的定义。 如果我像在链接描述文件中一样自己添加定义:

....
PROVIDE(__start_sym)
.symtab : { *(.symtab)}
PROVIDE(__end_sym)
....

__start_sym 和 __end_sym 的地址之间的差异为零,这意味着在输出文件。

但是 readelf 能够读取该部分并转储该部分的内容..如何?为什么 ?

I compile a simple program with gcc and if I see the section header using objdump, it does not show the section .symtab. for the same a.out file, readelf shows the section:

[25] .symtab           SYMTAB          00000000 000ca4 000480 10     26  2c  4
[26] .strtab           STRTAB          00000000 001124 00025c 00      0   0  1

Why?

In the default linker script I don't find a definition for .symtab section.
If I add a definition by myself like in the linker script :

....
PROVIDE(__start_sym)
.symtab : { *(.symtab)}
PROVIDE(__end_sym)
....

the difference b/w the addresses of __start_sym and __end_sym is zero, which means no such section is added in the output file.

But the readelf is able to read the section and dump the contents of this section .. How ? why ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸里的那抹悲凉 2024-09-11 16:41:41

当然,symtab 部分是存在的;这些工具只是以不同的方式提供信息。 symtab 被列为 objdump 中的动态部分(尝试 -x),以这种形式(或类似形式)

...
  STRTAB               0x08048408
  SYMTAB               0x08048178
  STRSZ                0x0000016d
...

Objdump 似乎更关注文件作为“对象”(允许例如反汇编),而 readelf更多关于 ELF 格式可以提供的信息,即文件“结构”本身。

Of course the symtab section is present; the tools just provide information in a different way. The symtab is listed as a dynamic section in objdump (try -x) in this form (or alike)

...
  STRTAB               0x08048408
  SYMTAB               0x08048178
  STRSZ                0x0000016d
...

Objdump seems more focusing on the file as "object" (allowing e.g. to disassemble too), while readelf more on the information ELF format can provide, i.e. on the file "structure" itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文