库中的函数符号

Symbols of function in a library

我知道这些命令:

readelf -sW alloc.o | awk ' == "FUNC"'

nm alloc.o | awk '=="T" || =="t"'

我可以获得库中使用的函数的名称。

但是,我如何区分库 USED 的函数和 DEFINED[=24= 的函数] 图书馆 ??

还有其他方法可以获取库定义的函数吗?

非常感谢!

I know with these commands: ... I can get the names of functions which are used in a library.

不,你不能。这些命令给你的是目标文件(或库)中定义的函数列表。

Is there another way to get functions DEFINED by a library

为什么你需要另一种方式?

how can I differentiate the functions which are USED by the library, and the functions which are DEFINED by the library

这取决于你所说的 "USED by the library" 是什么意思。一个典型的图书馆会使用一些它自己的功能,以及一些来自外部的功能。例如,包含 foo.obar.o 的库,其中 foo() 调用 bar(),而 bar() 调用外部 baz(),将如下所示:

 readelf -Ws libfoobar.a | egrep 'foo|bar|baz' | grep -v ' ABS'
File: libfoobar.a(foo.o)
     8: 0000000000000000    16 FUNC    GLOBAL DEFAULT    1 foo
     9: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND bar
File: libfoobar.a(bar.o)
     8: 0000000000000000    16 FUNC    GLOBAL DEFAULT    1 bar
     9: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND baz

这里可以看到foo.o定义了foo,使用了barbar.o 定义 bar 并使用 baz(未在此库中定义)。

你看不到的是 foo 是否被库使用(例如 foo 是否递归)。