$linuxjunkies
>

nm(1)

List symbols from object files and executables, showing their addresses, sizes, and types.

UbuntuDebianFedoraArch

Synopsis

nm [OPTION]... [FILE]...

Description

The nm command displays the symbol table of compiled object files, static libraries, and executables. Each symbol is listed with its address in hexadecimal, size, and type (function, data, section, etc.). This is essential for debugging, understanding code dependencies, and analyzing binaries.

Symbol types are shown as single characters: T for text (code) symbols, D for initialized data, B for uninitialized data, U for undefined symbols, A for absolute symbols, and others. Lowercase letters indicate local symbols; uppercase indicates global symbols.

Common options

FlagWhat it does
-aDisplay all symbols, including those with no address (normally omitted)
-CDemangle C++ symbol names for human-readable output
-dDisplay only dynamic symbols (from the dynamic symbol table)
-DDisplay dynamic symbols along with regular symbols
-gShow only global (external) symbols
-nSort symbols by address (default is by name)
-rSort symbols in reverse order
-SPrint symbol size instead of symbol address
-uDisplay only undefined symbols (symbols referenced but not defined)
-lInclude line number information from debugging symbols
-APrint file name and line number of each symbol using debugging info

Examples

List all symbols in the ls binary, sorted alphabetically by name

nm /bin/ls

Show symbols sorted by address with their memory locations

nm -n /bin/bash | head -20

Find all undefined symbols in an object file (what it needs from libraries)

nm -u myprogram.o

List demangled C++ symbols containing 'vector' from the standard library

nm -C libstdc++.so.6 | grep vector

Show only exported (global) symbols from an object file

nm -g mycode.o

Display the 10 largest symbols by size

nm -S myprogram | sort -k2 -nr | head -10

List symbols from all object files within a static library archive

nm libfoo.a

Count the number of dynamic symbols in the C library

nm -d /usr/lib/x86_64-linux-gnu/libc.so.6 | wc -l

Related commands