NM(1)

πŸ“¦
version 2.35.1 Β· 2 versions
, in debian bookworm, ubuntu noble, ubuntu resolute

πŸ’– NM(1) β€” GNU Development Tools πŸ’–

okay bestie, pull up a chair because we're about to talk about nm, the GNU Development Tools girlie whose whole job is listing symbols from object files. she's giving backstage-pass energy, she's giving x-ray vision, and honestly? iconic. let's get into it πŸ¦‹


✨ NAME ✨

nm β€” list symbols from object files. that's it, that's the gig. she looks inside your object files and tells you what's in there πŸ’…


✨ SYNOPSIS ✨

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]
   [--no-recurse-limit|--recurse-limit]]
   [--size-sort] [--special-syms]
   [--synthetic] [--with-symbol-versions] [--target=bfdname]
   [objfile...]

✨ DESCRIPTION ✨

so, GNU nm lists the symbols from object files objfile.... and listen β€” if you don't hand her any object files as arguments? she's just gonna assume the file a.out. no questions, no drama, that's the default bestie πŸŽ€

for every single symbol, nm shows you:

  • The symbol value, in the radix you picked with options (scroll down, we'll get there), or hexadecimal by default. no cap.
  • The symbol type. and at least the following types get used β€” plus others too, depending on what the object file format is feeling like that day. quick vibe check: if it's lowercase, the symbol is usually local; if it's UPPERCASE, the symbol is global (external). BUT β€” and this is the plot twist β€” there are a few lowercase symbols that show up for special global symbols: "u", "v" and "w". so don't get caught out πŸ™ˆ
    • "A" β€” the symbol's value is absolute, and it will not be changed by further linking. she said what she said, periodt.
    • "B" "b" β€” the symbol lives in the BSS data section. this section typically holds zero-initialized or uninitialized data, though the exact behavior is system dependent. ymmv bestie.
    • "C" β€” the symbol is common. common symbols are uninitialized data. when linking, multiple common symbols can show up with the same name. and if the symbol is defined anywhere, the common symbols get 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 let you access small data objects more efficiently β€” think a global int variable versus a big ol' global array. small but mighty πŸ’…
    • "i" β€” for PE format files this means the symbol is in a section specific to the implementation of DLLs. for ELF format files this means the symbol is an indirect function. and heads up β€” this is a GNU extension to the standard set of ELF symbol types. it means a symbol that, if referenced by a relocation, does not evaluate to its address β€” instead it must be invoked at runtime. the runtime execution will then return the value to be used in the relocation. she's doing all that at runtime, main character energy fr fr.
    • "I" β€” the symbol is an indirect reference to another symbol.
    • "N" β€” the symbol is a debugging symbol.
    • "n" β€” the symbol is in the read-only data section.
    • "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 or zero-initialized data section for small objects.
    • "T" "t" β€” the symbol is in the text (code) section. the classic ✨
    • "U" β€” the symbol is undefined.
    • "u" β€” the symbol is a unique global symbol. and guess what, this is a GNU extension to the standard set of ELF symbol bindings. for a symbol like this, the dynamic linker will make sure that in the entire process there is just one symbol with this name and type in use. one. single. icon. πŸ‘‘
    • "V" "v" β€” the symbol is a weak object. so here's the tea: when a weak defined symbol gets linked with a normal defined symbol, the normal defined symbol is used and there's no error. when a weak undefined symbol gets linked and the symbol isn't 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 gets linked with a normal defined symbol, the normal defined symbol is used with no error. when a weak undefined symbol gets linked and the symbol isn't defined, the value of the symbol is determined in a system-specific manner with no 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. mystery girlie πŸ•΅οΈβ™€οΈ
  • The symbol name. obviously πŸ’–

okay that's the vibe so far, but there is so much more coming β€” the options list is lowkey enormous and we are not skipping a single flag. stay tuned bestie, part 2 incoming 🫢

✨ OPTIONS ✨

okay bestie so the long forms and the short forms of these options are literally the same thing, they're just shown here as alternatives πŸ’… so pick whichever one your fingers vibe with.


  • -A, -o, --print-file-name β€” puts the name of the input file (or the archive member) right in front of each symbol, instead of doing the low-effort thing of naming the input file once at the top before all its symbols. name tags for every single symbol, main character energy πŸ‘‘
  • -a, --debug-syms β€” shows you all the symbols, even the debugger-only ones. normally those get gatekept and left off the list, but not today 🫢
  • -B β€” same as --format=bsd. it exists purely for compatibility with the MIPS nm, so it's giving legacy-but-iconic πŸ’œ
  • -C, --demangle[=style] β€” decodes (demangles) those crunchy low-level symbol names into human-readable user-level names 🧚 besides stripping off any leading underscore the system slapped on there, this makes C++ function names actually legible. and here's the tea: different compilers use different mangling styles, so you can pass the optional demangling style argument to pick the right style for your compiler. slay, customisation.
  • --no-demangle β€” do NOT demangle the low-level symbol names. this is the default, no cap.
  • --recurse-limit, --no-recurse-limit, --recursion-limit, --no-recursion-limit β€” turns a limit on recursion while demangling on or off. here's why that matters: since the name mangling formats allow for an infinite level of recursion, someone can absolutely craft strings whose decoding will eat up all the stack space on the host machine and trigger a memory fault 😭 the limit tries to stop that from happening by capping recursion at 2048 levels of nesting.

the default is for this limit to be enabled, but disabling it may be necessary if you genuinely need to demangle truly complicated names. but note β€” and I need you to hear me on this β€” if the recursion limit is disabled then stack exhaustion is possible, and any bug reports about such an event will be rejected. so like, you were warned, bestie πŸ™ˆ

  • -D, --dynamic β€” shows the dynamic symbols instead of the normal symbols. this only means anything for dynamic objects, like certain types of shared libraries. context-dependent queen ✨
  • -f format, --format=format β€” use the output format format, which can be "bsd", "sysv", or "posix". the default is "bsd". only the first character of format matters, and it can be upper or lower case β€” so efficient πŸ’…
  • -g, --extern-only β€” shows only external symbols. external only, we don't do internal here.
  • -h, --help β€” shows you a lil summary of all the nm options and dips out. the fastest way to get the rundown πŸƒβ™€οΈ
  • -l, --line-numbers β€” for each symbol, it uses debugging info to try and hunt down a filename and line number πŸ” for a defined symbol, it looks for the line number of the address of the symbol. 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 right after the other symbol info. receipts included, always.
  • --inlines β€” when -l is active, if the address belongs to a function that got inlined, this makes it print the source info for all the enclosing scopes back to the first non-inlined function too πŸ¦‹ for example, if "main" inlines "callee1" which inlines "callee2", and the address is from "callee2", then the source information for "callee1" and "main" gets printed as well. it's giving ancestry reveal.
  • -n, -v, --numeric-sort β€” sorts symbols numerically by their addresses instead of alphabetically by their names. numbers said first, periodt πŸ”’
  • -p, --no-sort β€” doesn't even bother sorting the symbols in any order, just prints them in the order it encountered them. chaotic, unbothered, living free 🌈
  • -P, --portability β€” uses the POSIX.2 standard output format instead of the default one. equivalent to -f posix. standards-compliant and proud of it ✨
  • -r, --reverse-sort β€” flips the sort order (numeric or alphabetic, whichever you picked), so the last one comes first. we're going backwards, it's a vibe πŸ’œ
  • -S, --print-size β€” prints both the value and the size of defined symbols, for the "bsd" output style. heads up though: this option has no effect for object formats that don't record symbol sizes β€” unless --size-sort is also used, in which case a calculated size gets displayed. conditional queen πŸ‘‘
  • -s, --print-armap β€” when you're listing symbols from archive members, this includes the index: a mapping (stored in the archive by ar or ranlib) of which modules contain definitions for which names. the archive's little address book πŸ“–
  • -t radix, --radix=radix β€” uses radix as the radix for printing the symbol values. it has to be d for decimal, o for octal, or x for hexadecimal. pick your numeral flavour πŸ“
  • -u, --undefined-only β€” shows only undefined symbols (the ones that are external to each object file). mysterious, unresolved, iconic πŸ’€
  • -V, --version β€” shows the version number of nm and exits. know your build, bestie.
  • -X β€” this option is ignored, kept only for compatibility with the AIX version of nm. it takes one parameter which must be the string 32_64. the default mode of AIX nm corresponds to -X 32, which is not supported by GNU nm. so it's here, it's decorative, don't count on it πŸŽ€
  • --defined-only β€” shows only defined symbols for each object file. the resolved ones, the ones with their life together.
  • --plugin name β€” loads the plugin called name to add support for extra target types. this option is only available if the toolchain was built with plugin support enabled.

if --plugin isn't provided but plugin support has been enabled, then nm iterates over the files in ${libdir}/bfd-plugins in alphabetical order, and the first plugin that claims the object in question gets used.

please note that this plugin search directory is not the one used by ld's -plugin option. to make nm use the linker plugin, it has to be copied 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 is called LLVMgold.so. the GCC plugin is always backwards compatible with earlier versions, so it's sufficient to just copy the newest one. 🫢
  • --size-sort β€” sorts symbols by size. for ELF objects the symbol sizes are read straight 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 gets printed rather than the value β€” and you must use -S for both size and value to be printed. teamwork makes the dream work πŸ’–
  • --special-syms β€” displays symbols that have a target-specific special meaning. these symbols are usually used by the target for some special processing, and they're normally not helpful when they show up in normal symbol lists. for example, for ARM targets this option would skip the mapping symbols used to mark transitions between ARM code, THUMB code and data. insider knowledge only iykyk πŸ”₯
  • --synthetic β€” includes synthetic symbols in the output. these are special symbols created by the linker for various purposes. they're not shown by default since they're not part of the binary's original source code. lore not in the original text, basically πŸ‘‘
  • --with-symbol-versions β€” enables display of symbol version information if any exists. the version string gets shown as a suffix on the symbol name, preceded by an @ character. for example foo@VER_1. and if the version is the default version to be used when resolving unversioned references to the symbol, then it's displayed as a suffix preceded by two @ characters. for example foo@@VER_2. double @ means it's the default, and that's the whole flex πŸ’…
  • --target=bfdname β€” specify an object code format other than your system's default format. going off-script, on purpose ✨
  • @file β€” reads command-line options from file. the options that get read are inserted in place of the original @file option. if file doesn't exist, or can't be read, then the option is treated literally and not removed. so like, no silent disappearing acts here.

options inside file are separated by whitespace. a whitespace character can be included in an option by surrounding the entire option in either single or double quotes. any character (including a backslash) can be included by prefixing the character to be included with a backslash. and file may itself contain additional @file options β€” any such options get processed recursively. it's files all the way down πŸ¦‹


🌸 SEE ALSO 🌸

ar(1), objdump(1), ranlib(1), and the Info entries for binutils.


Copyright (c) 1991-2020 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".


and that's the whole page bestie 🫢 this one's from binutils-2.35.1, dated 2022-11-21 β€” go forth and demangle responsibly, mwah πŸ’‹

πŸ“¦ where this page comes from