When developing software on Linux, you may deal with static libraries (files ending in .a
). These archives package compiled object files together, but sometimes you need to see what symbols (functions, variables, or other entities) they contain without extracting the files. This tutorial provides 2 methods how to view symbols from object files in static library on Linux.
Method 1 - nm command
The nm
tool lists symbols in object files. It's part of the standard Binutils package.
For example, to examine the /usr/lib/x86_64-linux-gnu/libz.a
static library, run the following command:
nm /usr/lib/x86_64-linux-gnu/libz.a
Example output (truncated):
adler32.o:
00000000000006d0 T adler32
00000000000006e0 T adler32_combine
00000000000007d0 T adler32_combine64
0000000000000000 T adler32_z
crc32.o:
00000000000006d0 T crc32
0000000000000700 T crc32_combine
0000000000000490 t crc32_combine_
0000000000000710 T crc32_combine64
0000000000000000 b crc32_func.0
0000000000000000 t crc32_little
00000000000006a0 T crc32_z
0000000000000000 r crc_table
0000000000000690 T get_crc_table
U __stack_chk_fail
...
By default, C++ function and class names in libraries are mangled - they include extra characters that encode parameter types, namespaces, and other details. This makes them difficult to interpret. The -C
option converts those names back into their human-readable form.
nm -C /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a
Method 2 - objdump command
The objdump
command (included in Binutils package) provides a more detailed view of the symbol table, along with section information. While nm
focuses only on listing symbols, objdump -t
also shows which section each symbol belongs to (e.g., .text
, .data
, etc.) and provides the symbol's size in bytes.
objdump -t /usr/lib/x86_64-linux-gnu/libz.a
Example output (truncated):
adler32.o: file format elf64-x86-64
SYMBOL TABLE:
0000000000000000 l d .text 0000000000000000 .text
0000000000000000 g F .text 00000000000006ce adler32_z
00000000000006d0 g F .text 000000000000000b adler32
00000000000006e0 g F .text 00000000000000e7 adler32_combine
00000000000007d0 g F .text 00000000000000e7 adler32_combine64
crc32.o: file format elf64-x86-64
SYMBOL TABLE:
0000000000000000 l d .text 0000000000000000 .text
0000000000000000 l d .bss 0000000000000000 .bss
0000000000000000 l F .text 0000000000000486 crc32_little
0000000000000000 l O .rodata 0000000000002000 crc_table
0000000000000490 l F .text 00000000000001fa crc32_combine_
0000000000000000 l O .bss 0000000000000008 crc32_func.0
0000000000000000 l d .rodata 0000000000000000 .rodata
0000000000000000 *UND* 0000000000000000 __stack_chk_fail
0000000000000690 g F .text 000000000000000c get_crc_table
00000000000006a0 g F .text 0000000000000028 crc32_z
00000000000006d0 g F .text 0000000000000028 crc32
0000000000000700 g F .text 0000000000000009 crc32_combine
0000000000000710 g F .text 0000000000000009 crc32_combine64
...
Just like nm
, objdump
also supports the -C
option for C++ demangling.
objdump -tC /usr/lib/gcc/x86_64-linux-gnu/11/libstdc++.a
Leave a Comment
Cancel reply