Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

nm (Unix)

From Wikipedia, the free encyclopedia
Unix command
nm
Original authorsDennis Ritchie,
Ken Thompson
(AT&T Bell Laboratories)
DevelopersVariousopen-source andcommercial developers
Initial releaseNovember 3, 1971; 54 years ago (1971-11-03)
Written inC
Operating systemUnix,Unix-like,Plan 9
PlatformCross-platform
TypeCommand
LicensePlan 9:MIT License

nm is aUnix command used to dump thesymbol table and their attributes from abinaryexecutable file (includinglibraries, compiledobject modules, shared-object files, and standaloneexecutables).

The output fromnm distinguishes between various symbol types. For example, it differentiates between afunction that is supplied by an object module and a function that is required by it.nm is used as an aid fordebugging, to help resolve problems arising from name conflicts andC++ name mangling, and to validate other parts of thetoolchain.

This command is shipped with a number of later versions ofUnix andsimilaroperating systems includingPlan 9. TheGNU Project ships an implementation ofnm as part of theGNU Binutils package.

The etymology is that in the old Version 7 Unix,nm's manpage used the termname list instead ofsymbol table.[1]

nm output sample

[edit]
/* * File name: test.c * For C code compile with: * gcc -c test.c * * For C++ code compile with: * g++ -c test.cpp */intglobal_var;intglobal_var_init=26;staticintstatic_var;staticintstatic_var_init=25;staticintstatic_function(){return0;}intglobal_function(intp){staticintlocal_static_var;staticintlocal_static_var_init=5;local_static_var=p;returnlocal_static_var_init+local_static_var;}intglobal_function2(){intx;inty;returnx+y;}#ifdef __cplusplusextern"C"#endifvoidnon_mangled_function(){// I do nothing}intmain(void){global_var=1;static_var=2;return0;}

If the previous code is compiled with thegcc C compiler, the output of thenm command is the following:

#nmtest.o0000000a T global_function00000025 T global_function200000004 C global_var00000000 D global_var_init00000004 b local_static_var.125500000008 d local_static_var_init.12560000003b T main00000036 T non_mangled_function00000000 t static_function00000000 b static_var00000004 d static_var_init

When the C++ compiler is used, the output differs:

#nmtest.o0000000a T _Z15global_functioni00000025 T _Z16global_function2v00000004 b _ZL10static_var00000000 t _ZL15static_functionv00000004 d _ZL15static_var_init00000008 b _ZZ15global_functioniE16local_static_var00000008 d _ZZ15global_functioniE21local_static_var_init         U __gxx_personality_v000000000 B global_var00000000 D global_var_init0000003b T main00000036 T non_mangled_function

The differences between the outputs also show an example of solving thename mangling problem by usingextern "C" in C++ code.

Symbol types
Symbol typeDescription
AGlobal absolute symbol
aLocal absolute symbol
BGlobal bss symbol
bLocal bss symbol
DGlobal data symbol
dLocal data symbol
fSource file name symbol
RGlobal read-only symbol
rLocal read-only symbol
TGlobal text symbol
tLocal text symbol
UUndefined symbol

See also

[edit]

References

[edit]
  1. ^"NM(1)".Unix Seventh Edition General Commands Manual.Archived from the original on 2026-01-05. Retrieved2025-03-14.

External links

[edit]
The WikibookGuide to Unix has a page on the topic of:Commands
File system
Processes
User environment
Text processing
Shell builtins
Searching
Documentation
Software development
Miscellaneous
File system
Processes
User environment
Text processing
Shell builtins
Networking
Searching
Software development
Miscellaneous
Stub icon

ThisUnix-related article is astub. You can help Wikipedia byadding missing information.

Retrieved from "https://en.wikipedia.org/w/index.php?title=Nm_(Unix)&oldid=1336334731"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp