Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I look inside a Linux .so or .a object and see what functions they contain?

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?

like image 325
interstar Avatar asked Aug 11 '16 04:08

interstar


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 a U. 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

like image 121
Kaz Avatar answered Oct 10 '22 12:10

Kaz


you can do nm Linux.so and it'll show the functions and variables inside the .so file.

like image 27
Chan Kim Avatar answered Oct 10 '22 13:10

Chan Kim