The linker can presumably do this, so is there a command-line tool to list functions in object files and tell me the names of functions and their signatures?
2 Answers
For a shared library, you have to use:
nm -D /path/to/libwhatever.so.<num>
Without the -D
, nm
dumps debug symbols; -D
refers to the dynamic symbols that are actually used for dynamic linking. From Ubuntu 12 session:
$ nm /lib/i386-linux-gnu/libc.so.6
nm: /lib/i386-linux-gnu/libc.so.6: no symbols
$ nm -D /lib/i386-linux-gnu/libc.so.6 | tail
0011fc20 T xdr_wrapstring
001202c0 T xdrmem_create
00115540 T xdrrec_create
001157f0 T xdrrec_endofrecord
00115740 T xdrrec_eof
00115690 T xdrrec_skiprecord
00120980 T xdrstdio_create
00120c70 T xencrypt
0011d330 T xprt_register
0011d450 T xprt_unregister
On this system libc.so
is stripped of debug symbols, so nm
shows nothing; but of course there are symbols for the dynamic linking mechanism revealed by nm -D
.
For a .a
archive or .o
object file, just nm
. The symbols are the symbols; if these files are stripped, these objects cannot be used for linking.
As covered in this similar question:
Exported sumbols are indicated by a
T
. Required symbols that must be loaded from other shared objects have aU
. Note that the symbol table does not include just functions, but exported variables as well.
Or if you only want to see exported symbols, add the
--defined-only
flag. eg:nm -D --defined-only /lib/libtest.so

- 5,226
- 5
- 36
- 66

- 55,781
- 9
- 100
- 149
-
What is U, R, T each explaining ? (your here is only T) – Nov 13 '20 at 09:36
-
@klenteed R means the symbol is in a read-only data section. U means undefined symbol (reference to a symbol that has to come from somewhere else). T means that the symbol is in the text section (i.e. code). – Kaz Nov 13 '20 at 18:27
you can do nm Linux.so
and it'll show the functions and variables inside the .so file.

- 5,177
- 12
- 57
- 112
-
Likewise for a `.o` or `.a` (static archive) file. There are options to tell you which object files within an `.a` file contain which symbols, too. – Jonathan Leffler Aug 11 '16 at 04:43
-
2