nm (Name List) Command Cheatsheet
Installation Instructions
# Using MinGW
pacman -S binutils # If using MSYS2
# Or via Chocolatey
choco install mingw-w64
# Debian/Ubuntu
sudo apt-get install binutils
# RHEL/CentOS
sudo yum install binutils
# Arch Linux
sudo pacman -S binutils
# Using Homebrew
brew install binutils
# Command might be available as 'gnm'
List all symbols:
Show dynamic symbols:
Show debug symbols:
nm --debug-syms binary_file
Symbol Types and Filtering
Show only external symbols:
Show only undefined symbols:
Show only defined symbols:
Sort symbols by address:
Sort symbols alphabetically:
Display size of symbols:
nm --size-sort binary_file
Show symbol value and size:
nm --print-size binary_file
Display in BSD format:
Display in POSIX format:
Show only functions:
nm binary_file | grep -w " T"
Show only global variables:
nm binary_file | grep -w " D"
Show only static symbols:
nm binary_file | grep -w " t"
Demangle C++ symbols:
nm --demangle binary_file
Show symbol types:
Print line numbers:
nm --line-numbers binary_file
Process multiple files:
Show filename with symbols:
nm --print-file-name file1.o file2.o
Find main function:
nm binary_file | grep " main$"
List all constructors:
nm binary_file | grep " _init"
List all destructors:
nm binary_file | grep " _fini"
Generate output in portable format:
nm -P --portability binary_file
Show synthetic symbols:
nm --synthetic binary_file
Show all symbols with addresses:
Integration with Other Tools
Sort by symbol size:
nm --print-size --size-sort binary_file
Format output for processing:
nm -p -g binary_file | cut -d' ' -f3
Count symbols by type:
nm binary_file | awk ' {print $2}' | sort | uniq -c
Find weak symbols:
nm binary_file | grep " W "
List read-only data:
nm binary_file | grep " R "
Find unitialized data:
nm binary_file | grep " B "
Architecture-Specific Options
Display 32-bit format:
Display 64-bit format:
Show target specific symbol types:
nm --target=target_type binary_file
Show debugging symbols only:
nm --debug-syms binary_file
Show demangled symbols with types:
nm -C --demangle binary_file
Display symbol versions:
nm --version-info binary_file
Export and Import Analysis
List imported functions:
nm -D --undefined-only binary_file
List exported functions:
nm -D --defined-only binary_file
Show only private symbols:
nm --private-symbols binary_file
Show only public symbols:
nm --public-symbols binary_file
List external symbols:
nm --extern-only binary_file
Find thread-local symbols:
nm binary_file | grep " TLS "
List common symbols:
nm binary_file | grep " C "
Show absolute symbols:
nm binary_file | grep " A "
Generate wide output:
Show numeric radix:
nm -t d binary_file # decimal
nm -t x binary_file # hexadecimal
nm -t o binary_file # octal
List archive symbols:
nm --print-armap archive.a
Process all archive members:
nm --print-file-name archive.a