NM(1)
π 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 ana.outobject file. in this case, the next values printed are thestabs otherfield, thestabs descfield, and thestab 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 MIPSnm, 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 thenmoptions 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-lis 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-sortis 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 byarorranlib) 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 bedfor decimal,ofor octal, orxfor 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 ofnmand exits. know your build, bestie.-Xβ this option is ignored, kept only for compatibility with the AIX version ofnm. it takes one parameter which must be the string32_64. the default mode of AIXnmcorresponds to-X 32, which is not supported by GNUnm. 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 byld's-pluginoption. to makenmuse the linker plugin, it has to be copied into the${libdir}/bfd-pluginsdirectory. for GCC based compilations the linker plugin is calledliblto_plugin.so.0.0.0. for Clang based compilations it is calledLLVMgold.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-Sfor 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 examplefoo@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 examplefoo@@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@fileoption. 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 π
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
- debian bookworm: binutils-djgpp 2.35.1+dfsg-2 Β· GPL-3.0-or-later
- ubuntu noble: binutils-djgpp 2.35.1+dfsg-2 Β· GPL-3.0-or-later
- ubuntu resolute: binutils-djgpp 2.35.1+dfsg-2 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms