Linux nm 与“readelf -s”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9961473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
nm vs "readelf -s"
提问by camino
Suppose we have a shared library named libtest.so, there is one function "foo" in it
假设我们有一个名为 libtest.so 的共享库,其中有一个函数“foo”
use the strip to discards all symbols from libtest.so
使用条带丢弃 libtest.so 中的所有符号
$strip libtest.so
so ,now if we use:
所以,现在如果我们使用:
$nm libtest.so
it will print out:
它会打印出:
nm: libtest.so: no symbols
nm:libtest.so:无符号
but if we use :
但如果我们使用:
$readelf -s libtest.so
foo function still can be seen from its result:
foo 函数仍然可以从其结果中看出:
...
...
10: 000005dc 5 FUNC GLOBAL DEFAULT 12 _Z3foov
10: 000005dc 5 FUNC 全局默认值 12 _Z3foov
...
...
we also can use command strings to check it:
我们也可以使用命令字符串来检查它:
$strings libtest.so
...
...
_Z3foov
_Z3fov
...
...
here is my question ,why nm give no result for striped libtest.so?
这是我的问题,为什么 nm 没有给出条纹 libtest.so 的结果?
Thanks
谢谢
采纳答案by Employed Russian
why nm give no result for striped libtest.so
为什么 nm 没有给出条纹 libtest.so 的结果
There are twosymbol tables in the original libtest.so
: a "regular" one (in .symtab
and .strtab
sections) and a dynamic one (in .dynsym
and .dynstr
sections).
原始符号表有两个libtest.so
:“常规”符号表(in.symtab
和.strtab
sections)和动态符号表(in.dynsym
和.dynstr
sections)。
If strip
removed both symbol tables, you library would be completely useless: the dynamic loader couldn't resolve any symbols in it. So strip
does the only thing that makes sense: removes the "regular" symbol table, leaving the dynamic one intact.
如果strip
删除两个符号表,您的库将完全无用:动态加载器无法解析其中的任何符号。所以,strip
做有意义的唯一的事:删除“常规”符号表,使动态的完整无缺。
You can see symbols in the dynamic symbol table with nm -D
or readelf -s
.
您可以使用nm -D
或来查看动态符号表中的符号readelf -s
。
The "regular" symbol table is useful only for debugging (for example, it contains entries for static functions, which are not exported by the library, and do not show up in the dynamic symbol table).
“常规”符号表仅用于调试(例如,它包含静态函数的条目,这些条目不是由库导出的,也不会出现在动态符号表中)。
But the dynamic loader never looks at the "regular" symbol table (which is not in a format suitable for fast symbol lookups); only at the dynamic one. So the "regular" symbol table is not needed for correct program operation, but the dynamic one is.
但是动态加载器从不查看“常规”符号表(其格式不适合快速符号查找);只有在动态的。因此,正确的程序操作不需要“常规”符号表,但动态符号表需要。