readelf -sD 和 readelf --dyn-syms 有什么区别

发布于 2025-01-19 17:24:18 字数 1822 浏览 2 评论 0原文

从Readelf的manpage中,我可以看到,

--dyn-syms             Display the dynamic symbol table
-s --syms              Display the symbol table
-D --use-dynamic       Use the dynamic section info when displaying symbols

所以我认为readelf -sd等于readelf -dyn -syms。但是,当我在CentOS 7中进行测试时,它给出以下结果。我想知道为什么?

$readelf -sD a

Symbol table for image:
  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name
    6   0: 0000000000400580     0 FUNC    GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev
    2   0: 0000000000000000     0 NOTYPE  WEAK   DEFAULT UND __gmon_start__
    5   1: 0000000000000000     0 FUNC    GLOBAL DEFAULT UND __cxa_atexit
    4   1: 0000000000000000     0 FUNC    GLOBAL DEFAULT UND __libc_start_main
    3   1: 0000000000000000     0 FUNC    GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev
    1   2: 0000000000000000     0 FUNC    GLOBAL DEFAULT UND printf

readelf --dyn-syms a

Symbol table '.dynsym' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND printf@GLIBC_2.2.5 (2)
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     3: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (3)
     4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.2.5 (2)
     5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_atexit@GLIBC_2.2.5 (2)
     6: 0000000000400580     0 FUNC    GLOBAL DEFAULT  UND _ZNSt8ios_base4InitD1Ev@GLIBCXX_3.4 (3)

ps a是从以下代码中编译的,g ++ a.cpp -o a与GCC 7.3.0编译

#include <iostream>

int main() {
    printf("aaa");
}

From readelf's manpage, I see that

--dyn-syms             Display the dynamic symbol table
-s --syms              Display the symbol table
-D --use-dynamic       Use the dynamic section info when displaying symbols

So I think readelf -sD equals readelf --dyn-syms. However, when I test in CentOS 7, it gives the following result. I wonder why?

$readelf -sD a

Symbol table for image:
  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name
    6   0: 0000000000400580     0 FUNC    GLOBAL DEFAULT UND _ZNSt8ios_base4InitD1Ev
    2   0: 0000000000000000     0 NOTYPE  WEAK   DEFAULT UND __gmon_start__
    5   1: 0000000000000000     0 FUNC    GLOBAL DEFAULT UND __cxa_atexit
    4   1: 0000000000000000     0 FUNC    GLOBAL DEFAULT UND __libc_start_main
    3   1: 0000000000000000     0 FUNC    GLOBAL DEFAULT UND _ZNSt8ios_base4InitC1Ev
    1   2: 0000000000000000     0 FUNC    GLOBAL DEFAULT UND printf

readelf --dyn-syms a

Symbol table '.dynsym' contains 7 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND printf@GLIBC_2.2.5 (2)
     2: 0000000000000000     0 NOTYPE  WEAK   DEFAULT  UND __gmon_start__
     3: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSt8ios_base4InitC1Ev@GLIBCXX_3.4 (3)
     4: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __libc_start_main@GLIBC_2.2.5 (2)
     5: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_atexit@GLIBC_2.2.5 (2)
     6: 0000000000400580     0 FUNC    GLOBAL DEFAULT  UND _ZNSt8ios_base4InitD1Ev@GLIBCXX_3.4 (3)

P.S. a is compiled from the following code, with GCC 7.3.0 by g++ a.cpp -o a

#include <iostream>

int main() {
    printf("aaa");
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文