NM(1)

πŸ“¦ version 12.2.0, in nixpkgs unstable

πŸ’… NAME πŸ’…

nm β€” list symbols from object files.

Okay bestie, welcome to the NM(1) page from the GNU Development Tools manual. This is the whole vibe for nm, the tool that lists symbols from object files. No cap, it's giving β€œbinary detective” energy. πŸ”βœ¨

πŸŽ€ SYNOPSIS πŸŽ€

Here's the exact command shape, character for character:

nm [-A|-o|--print-file-name] [-a|--debug-syms]
   [-B|--format=bsd] [-C|--demangle[=style]]
   [-D|--dynamic] [-fformat|--format=format]
   [-g|--extern-only] [-h|--help]
   [-l|--line-numbers] [--inlines]
   [-n|-v|--numeric-sort]
   [-P|--portability] [-p|--no-sort]
   [-r|--reverse-sort] [-S|--print-size]
   [-s|--print-armap] [-t radix|--radix=radix]
   [-u|--undefined-only] [-V|--version]
   [-X 32_64] [--defined-only] [--no-demangle]
   [--plugin name] [--size-sort] [--special-syms]
   [--synthetic] [--with-symbol-versions] [--target=bfdname]
   [objfile...]

🌸 DESCRIPTION 🌸

Okay so GNU nm lists the symbols from object files objfile.... If no object files are listed as arguments, nm assumes the file a.out. πŸ’–

For each symbol, nm shows:

  • The symbol value β€” in the radix selected by options (see below), or hexadecimal by default.
  • The symbol type β€” at least the following types are used; others are, as well, depending on the object file format. If lowercase, the symbol is usually local; if uppercase, the symbol is global (external). There are however a few lowercase symbols that are shown for special global symbols (u, v and w).
    • A β€” The symbol's value is absolute, and will not be changed by further linking.
    • B, b β€” The symbol is in the uninitialized data section (known as BSS).
    • C β€” The symbol is common. Common symbols are uninitialized data. When linking, multiple common symbols may appear with the same name. If the symbol is defined anywhere, the common symbols are treated as undefined references.
    • D, d β€” The symbol is in the initialized data section.
    • G, g β€” The symbol is in an initialized data section for small objects. Some object file formats permit more efficient access to small data objects, such as a global int variable as opposed to a large global array.
    • i β€” For PE format files this indicates that the symbol is in a section specific to the implementation of DLLs. For ELF format files this indicates that the symbol is an indirect function. This is a GNU extension to the standard set of ELF symbol types. It indicates a symbol which if referenced by a relocation does not evaluate to its address, but instead must be invoked at runtime. The runtime execution will then return the value to be used in the relocation.
    • I β€” The symbol is an indirect reference to another symbol.
    • N β€” The symbol is a debugging symbol.
    • p β€” The symbol is in a stack unwind section.
    • R, r β€” The symbol is in a read only data section.
    • S, s β€” The symbol is in an uninitialized data section for small objects.
    • T, t β€” The symbol is in the text (code) section.
    • U β€” The symbol is undefined.
    • u β€” The symbol is a unique global symbol. This is a GNU extension to the standard set of ELF symbol bindings. For such a symbol the dynamic linker will make sure that in the entire process there is just one symbol with this name and type in use.
    • V, v β€” The symbol is a weak object. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the weak symbol becomes zero with no error. On some systems, uppercase indicates that a default value has been specified.
    • W, w β€” The symbol is a weak symbol that has not been specifically tagged as a weak object symbol. When a weak defined symbol is linked with a normal defined symbol, the normal defined symbol is used with no error. When a weak undefined symbol is linked and the symbol is not defined, the value of the symbol is determined in a system-specific manner without error. On some systems, uppercase indicates that a default value has been specified.
    • - β€” The symbol is a stabs symbol in an a.out object file. In this case, the next values printed are the stabs other field, the stabs desc field, and the stab type. Stabs symbols are used to hold debugging information.
    • ? β€” The symbol type is unknown, or object file format specific.
  • The symbol name.

✨ OPTIONS ✨

Okay bestie, gather round πŸ’– so real talk: the long and short forms of options are literally equivalent. Same vibe, different spelling. You can use whichever one feels right in your heart.

  • -A, -o, --print-file-name β€” puts the name of the input file (or archive member) right before each symbol, so you can see where it came from. Like a little name tag 🏷️. Instead of doing the boring thing of naming the input file once at the top before all its symbols.
  • -a, --debug-syms β€” shows you all the symbols, even the debugger-only ones. Those ones? Normally they stay hidden. πŸ™ˆ
  • -B β€” literally just the same as --format=bsd. It's there for compatibility with the MIPS nm. That's it, that's the whole personality.
  • -C, --demangle[=style] β€” decodes (demangles) those cursed low-level symbol names into names a human can actually read. Not only does it strip the initial underscore the system slapped on there, it also makes C++ function names readable, which is honestly a public service 😭. Different compilers mangle in different styles, so the optional style argument lets you pick the right demangling style for your compiler.
  • --no-demangle β€” does not demangle low-level symbol names. Fun fact: this is the default. πŸ’…
  • -D, --dynamic β€” shows the dynamic symbols instead of the normal ones. Heads up: this only means anything for dynamic objects, like certain types of shared libraries.
  • -f format, --format=format β€” uses output format format, and format can be "bsd", "sysv", or "posix". Default is "bsd". Also: only the *first character of *format matters, and it can be upper or lower case. Shortcut city.
  • -g, --extern-only β€” shows only external symbols. External babes only ✨.
  • -h, --help β€” shows a summary of the nm options and dips. 🫢
  • -l, --line-numbers β€” for each symbol it uses the debugging info to try to find a filename and line number. For a defined symbol, it looks for the line number of the symbol's address. For an undefined symbol, it looks for the line number of a relocation entry that refers to the symbol. And if it does find line number info? It prints it after all the other symbol info.
  • --inlines β€” when -l is active and the address belongs to a function that got inlined, this option makes it print the source info for all the enclosing scopes, all the way back to the first non-inlined function. The example is kinda iconic: if "main" inlines "callee1", and "callee1" inlines "callee2", and the address is from "callee2", then the source info for "callee1" and "main" gets printed too. Nesting reveal πŸ”₯.
  • -n, -v, --numeric-sort β€” sorts the symbols numerically by their addresses instead of alphabetically by their names. Numbers over letters, always.
  • -p, --no-sort β€” doesn't even bother sorting. No order, no rules, just prints them in the order encountered. Chaos, but make it intentional. πŸ’€
  • -P, --portability β€” uses the POSIX.2 standard output format instead of the default. Equivalent to -f posix.
  • -r, --reverse-sort β€” flips the sort order (numeric or alphabetic, whichever you picked). The last come first. Backwards slay. πŸ”„
  • -S, --print-size β€” prints both the value and the size of defined symbols for the "bsd" output style. Warning bestie: this option does nothing for object formats that don't record symbol sizes β€” unless --size-sort is also used, in which case you get a calculated size instead.
  • -s, --print-armap β€” when listing symbols from archive members, this includes the index: that's the mapping (stored in the archive by ar or ranlib) of which modules contain definitions for which names. Receipts, basically. 🧾
  • -t radix, *--radix=radix* β€” uses radix as the radix for printing symbol values. Rules are strict, no negotiating: d for decimal, o for octal, or x for hexadecimal.
  • -u, --undefined-only β€” shows only undefined symbols (the ones external to each object file). The mystery symbols, if you will. πŸ¦‹
  • -V, --version β€” shows the version number of nm and exits.
  • -X β€” honestly? Ignored. It exists for compatibility with the AIX version of nm. It takes one parameter, which must be the string 32_64. Here's the lore: the default mode of AIX nm corresponds to -X 32, and that one is not supported by GNU nm. So yeah. Ignored.
  • --defined-only β€” shows only the defined symbols for each object file.
  • --plugin name β€” loads the plugin called name so you can add support for extra target types. Small catch: this option is only available if the toolchain was built with plugin support enabled.

If you don't pass --plugin but plugin support is enabled, then nm iterates over the files in ${libdir}/bfd-plugins in alphabetic order, and the first plugin that claims the object in question gets used.

Real talk ⚠️: this plugin search directory is not the same one used by ld's -plugin option. If you want nm to use the linker plugin, you have to copy it into the ${libdir}/bfd-plugins directory. For GCC based compilations the linker plugin is called liblto_plugin.so.0.0.0. For Clang based compilations it's called LLVMgold.so. Good news though: the GCC plugin is always backwards compatible with earlier versions, so copying the newest one is enough. πŸ’…
  • --size-sort β€” sorts symbols by size. For ELF objects the symbol sizes are read from the ELF; for other object types the symbol sizes are computed as the difference between the value of the symbol and the value of the symbol with the next higher value. And if the "bsd" output format is being used, the size of the symbol is printed rather than the value β€” and -S must be used if you want both size and value printed.
  • --special-syms β€” displays symbols that have a target-specific special meaning. These ones are usually used by the target for some special processing and they're not normally helpful when they show up in normal symbol lists. Example for the ARM girlies: for ARM targets this option would skip the mapping symbols used to mark transitions between ARM code, THUMB code and data.
  • --synthetic β€” includes synthetic symbols in the output. These are special symbols created by the linker for various purposes, and they're not shown by default because they're not part of the binary's original source code. Not canon, as it were. 😌
  • --with-symbol-versions β€” enables display of symbol version info if any exists. The version string shows up as a suffix to the symbol name, preceded by an @ character. Example: foo@VER_1. And if that version is the default version used when resolving unversioned references to the symbol, it's displayed as a suffix preceded by two @ characters. Example: foo@@VER_2. Double at-sign, extra iconic. ✨
  • --target=bfdname β€” specifies an object code format other than your system's default format.
  • @file β€” reads command-line options from file. The options it reads get inserted in place of the original @file option. And if file doesn't exist, or can't be read, then the option is treated literally and not removed. 🫢

Options inside file are separated by whitespace. A whitespace character can be included in an option by wrapping the entire option in either single or double quotes. Any character (including a backslash) can be included by prefixing it with a backslash. And plot twist: the file itself may contain additional @file options, and any of those get processed recursively. It's turtles all the way down 🐒.


🌸 SEE ALSO 🌸

ar(1), objdump(1), ranlib(1), and the Info entries for binutils. Go read your siblings' pages, they're lovely. πŸ’œ


Copyright (c) 1991-2018 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

Ngl that's the legal bit and you do have to read it, bestie. No skipping. πŸ“œ

Okay that's the whole page, you made it πŸŽ€ This one's from binutils-2.30, dated 2018-01-27 β€” vintage but still serving looks. Go forth and nm something, mwah πŸ’–

πŸ“¦ where this page comes from