nm Command

Purpose

Displays information about symbols in object files, executable files, and object-file libraries.

Syntax

nm [ -A ] [ -C ] [ -X {32|64|32_64|d64| any}] [ -f ] [ -h ] [ -l ] [ -p ] [ -r ] [ -T ] [ -v ] [ -B | -P ] [ -e | -g | -u ] [ -d | -o | -x | -t Format ] File ...

Description

The nm command displays information about symbols in the specified File, which can be an object file, an executable file, or an object-file library. If the file contains no symbol information, the nm command reports the fact, but does not interpret it as an error condition. The nm command reports numerical values in decimal notation by default.

The nm command writes the following symbol information to standard output:

Flags

Item Description
-A Displays either the full path name or library name of an object on each line.
-B Displays output in the Berkeley Software Distribution (BSD) format:
value   type   name
-C Suppresses the demangling of C++ names. The default is to demangle all C++ symbol names.
Note: Symbols from C++ object files have their names demangled before they are used.
-d Displays a symbol's value and size as a decimal. This is the default.
-e Displays only static and external (global) symbols.
-f Displays full output, including redundant .text, .data, and .bss symbols, which are normally suppressed.
-g Displays only external (global) symbols.
-h Suppresses the display of output header data.
-l Distinguishes between WEAK and GLOBAL symbols by appending a * to the key letter for WEAK symbols. If used with the -P option, the symbol type for weak symbols is represented as follows:
V
Weak Data Symbol
W
Weak Text Symbol
w
Weak Undefined Symbol
Z
Weak bss Symbol
-o Displays a symbol's value and size as an octal rather than a decimal number.
-P Displays information in a standard portable output format:
library/object name   name   type   value   size

This format displays numerical values in hexadecimal notation, unless you specify a different format with the -t, -d, or -o flags.

The -P flag displays the library/object name field only if you specify the -A flag. Also, the -P flag displays the size field only for symbols for which size is applicable.

-p Does not sort. The ouput is printed in symbol-table order.
-r Sorts in reverse order.
-t Format Displays numerical values in the specified format, where the Format parameter is one of the following notations:
d
Decimal notation. This is the default format for the nm command.
o
Octal notation.
x
Hexadecimal notation.
-T Truncates every name that would otherwise overflow its column, making the last character displayed in the name an asterisk. By default, nm displays the entire name of the symbols listed, and a name that is longer than the width of the column set aside for it causes every column after the name to be misaligned.
-u Displays only undefined symbols.
-v Sorts output by value instead of alphabetically.
-x Displays a symbol's value and size as a hexadecimal rather than a decimal number.
-X mode Specifies the type of object file nm should examine. The mode must be one of the following:
32
Processes only 32-bit object files
64
Processes only 64-bit object files
32_64
Processes both 32-bit and 64-bit object files
d64
Examines discontinued 64-bit XCOFF files (magic number == U803XTOCMAGIC).
any
Processes all of the supported object files.

The default is to process 32-bit object files (ignore 64-bit objects). The mode can also be set with the OBJECT_MODE environment variable. For example, OBJECT_MODE=64 causes nm to process any 64-bit objects and ignore 32-bit objects. The -X flag overrides the OBJECT_MODE variable.

Note: The nm command supports the (double hyphen) flag. This flag distinguishes a File operand if the file name can be misinterpreted as an option. For example, to specify a file name that begins with a hyphen, use the flag.

Exit Status

This command returns the following exit values:

Item Description
0 Successful completion.
>0 An error occurred.

Examples

  1. To list the static and external symbols of the object file a.out, enter:
    nm -e a.out
  2. To display symbol sizes and values as hexadecimal and sort the symbols by value, enter:
    nm -xv a.out
  3. To display symbol of all 64-bit objects in libc.a, ignoring all 32-bit objects:
    nm -X64 /usr/lib/libc.a

Files

Item Description
/usr/ccs/bin/nm Contains the nm command.