nm(1)
List symbols from object files and executables, showing their addresses, sizes, and types.
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
| Flag | What it does |
|---|---|
-a | Display all symbols, including those with no address (normally omitted) |
-C | Demangle C++ symbol names for human-readable output |
-d | Display only dynamic symbols (from the dynamic symbol table) |
-D | Display dynamic symbols along with regular symbols |
-g | Show only global (external) symbols |
-n | Sort symbols by address (default is by name) |
-r | Sort symbols in reverse order |
-S | Print symbol size instead of symbol address |
-u | Display only undefined symbols (symbols referenced but not defined) |
-l | Include line number information from debugging symbols |
-A | Print 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/lsShow symbols sorted by address with their memory locations
nm -n /bin/bash | head -20Find all undefined symbols in an object file (what it needs from libraries)
nm -u myprogram.oList demangled C++ symbols containing 'vector' from the standard library
nm -C libstdc++.so.6 | grep vectorShow only exported (global) symbols from an object file
nm -g mycode.oDisplay the 10 largest symbols by size
nm -S myprogram | sort -k2 -nr | head -10List symbols from all object files within a static library archive
nm libfoo.aCount the number of dynamic symbols in the C library
nm -d /usr/lib/x86_64-linux-gnu/libc.so.6 | wc -l