List symbols in a .so file
Do not miss this exclusive book on Binary Tree Problems. Get it now for free.
In this article, we have presented different commands which can be used to list all or specific symbols in a given shared object .so file. This involve different commands with nm, objdump and readelf.
Table of contents:
- 4 commands with nm
- objdump command
- readelf command
The different commands to list different symbols in a given shared object (.so) file are as follows:
4 commands with nm
- To see all symbols in a given so file:
nm --demangle --dynamic <lib.so>
nm is a tool that comes with binutils. To install binutils, use the following steps.
- To see only symbols that are defined in an .so file (skipping the undefined symbols), use:
nm --demangle --dynamic --defined-only <lib.so>
- To see only symbols which are available for linking (internal linkage), use:
nm --demangle --dynamic --extern-only <lib.so>
- To see symbols which are defined and available for linking, use:
nm --demangle --dynamic --defined-only --extern-only <lib.so>
- To find a specific symbol in the above list, use grep with the command like:
nm --demangle --dynamic --defined-only --extern-only <lib.so> | grep <search>
objdump command
To get the list of symbols in a given .so file using objdump command, use the following:
objdump -TC <lib.so>
readelf command
If the shared object .so file is in ELF format, one can use readelf command as follows to list the symbols:
readelf -Ws <lib.so>
This will list all symbols including the ones in shared objects referenced by the current .so file. To get the symbols in the current .so file, we need to check the information in the 7th column which can be extracted using awk command as follows:
readelf -Ws <lib.so> | awk '{print $8}';
With these commands presented in this article at OpenGenus, you must have a complete idea of how to list the different symbols in a given .so file. You can use this information for debugging "symbol not found" error.
Sign up for FREE 3 months of Amazon Music. YOU MUST NOT MISS.