Original author(s) | Dennis Ritchie, Ken Thompson (AT&T Bell Laboratories) |
---|---|
Developer(s) | Various open-source and commercial developers |
Initial release | November 3, 1971 |
Written in | C |
Operating system | Unix, Unix-like, Plan 9 |
Platform | Cross-platform |
Type | Command |
License | Plan 9: MIT License |
nm
is a Unix command used to dump the symbol table and their attributes from a binary executable file (including libraries, compiled object modules, shared-object files, and standalone executables).
The output from nm
distinguishes between various symbol types. For example, it differentiates between a function that is supplied by an object module and a function that is required by it. nm
is used as an aid for debugging, to help resolve problems arising from name conflicts and C++ name mangling, and to validate other parts of the toolchain.
This command is shipped with a number of later versions of Unix and similar operating systems including Plan 9. The GNU Project ships an implementation of nm
as part of the GNU Binutils package.
/* * 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 the gcc C compiler, the output of the nm
command is the following:
# nmtest.o 0000000a 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.o 0000000a 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 the name mangling problem by using extern "C" in C++ code.
Symbol type | Description |
---|---|
A | Global absolute symbol |
a | Local absolute symbol |
B | Global bss symbol |
b | Local bss symbol |
D | Global data symbol |
d | Local data symbol |
f | Source file name symbol |
L | Global thread-local symbol (TLS) |
l | Static thread-local symbol (TLS) |
R | Global read-only symbol |
r | Local read-only symbol |
T | Global text symbol |
t | Local text symbol |
U | Undefined symbol |
C is a general-purpose programming language. It was created in the 1970s by Dennis Ritchie and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems code, device drivers, and protocol stacks, but its use in application software has been decreasing. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.
In software development, Make is a command-line interface software tool that performs actions ordered by configured dependencies as defined in a configuration file called a makefile. It is commonly used for build automation to build executable code from source code. But, not limited to building, Make can perform any operation available via the operating system shell.
D, also known as dlang, is a multi-paradigm system programming language created by Walter Bright at Digital Mars and released in 2001. Andrei Alexandrescu joined the design and development effort in 2007. Though it originated as a re-engineering of C++, D is now a very different language. As it has developed, it has drawn inspiration from other high-level programming languages. Notably, it has been influenced by Java, Python, Ruby, C#, and Eiffel.
In computer programming, a global variable is a variable with global scope, meaning that it is visible throughout the program, unless shadowed. The set of all global variables is known as the global environment or global state. In compiled languages, global variables are generally static variables, whose extent (lifetime) is the entire runtime of the program, though in interpreted languages, global variables are generally dynamically allocated when declared, since they are not known ahead of time.
In the C and C++ programming languages, an inline function is one qualified with the keyword inline
; this serves two purposes:
register
storage class specifier, which similarly provides an optimization hint.inline
is to change linkage behavior; the details of this are complicated. This is necessary due to the C/C++ separate compilation + linkage model, specifically because the definition (body) of the function must be duplicated in all translation units where it is used, to allow inlining during compiling, which, if the function has external linkage, causes a collision during linking. C and C++ resolve this in different ways.printf is a C standard library function that formats text and writes it to standard output.
In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier, constant, procedure and function in a program's source code is associated with information relating to its declaration or appearance in the source. In other words, the entries of a symbol table store the information related to the entry's corresponding symbol.
The Simplified Wrapper and Interface Generator (SWIG) is an open-source software tool used to connect computer programs or libraries written in C or C++ with scripting languages such as Lua, Perl, PHP, Python, R, Ruby, Tcl, and other language implementations like C#, Java, JavaScript, Go, D, OCaml, Octave, Scilab and Scheme. Output can also be in the form of XML.
In compiler construction, name mangling is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern programming languages.
In computer programming, thread-local storage (TLS) is a memory management method that uses static or global memory local to a thread. The concept allows storage of data that appears to be global in a system with separate threads.
IP Pascal is an implementation of the Pascal programming language using the IP portability platform, a multiple machine, operating system and language implementation system. It implements the language "Pascaline", and has passed the Pascal Validation Suite.
In computer programming, the term hooking covers a range of techniques used to alter or augment the behaviour of an operating system, of applications, or of other software components by intercepting function calls or messages or events passed between software components. Code that handles such intercepted function calls, events or messages is called a hook.
The C and C++ programming languages are closely related but have many significant differences. C++ began as a fork of an early, pre-standardized C, and was designed to be mostly source-and-link compatible with C compilers of the time. Due to this, development tools for the two languages are often integrated into a single product, with the programmer able to specify C or C++ as their source language.
Interprocedural optimization (IPO) is a collection of compiler techniques used in computer programming to improve performance in programs containing many frequently used functions of small or medium length. IPO differs from other compiler optimizations by analyzing the entire program as opposed to a single function or block of code.
In computer programming, DLL injection is a technique used for running code within the address space of another process by forcing it to load a dynamic-link library. DLL injection is often used by external programs to influence the behavior of another program in a way its authors did not anticipate or intend. For example, the injected code could hook system function calls, or read the contents of password textboxes, which cannot be done the usual way. A program used to inject arbitrary code into arbitrary processes is called a DLL injector.
Haxe is a high-level cross-platform programming language and compiler that can produce applications and source code for many different computing platforms from one code-base. It is free and open-source software, released under an MIT License. The compiler, written in OCaml, is released under the GNU General Public License (GPL) version 2.
A weak symbol denotes a specially annotated symbol during linking of Executable and Linkable Format (ELF) object files. By default, without any annotation, a symbol in an object file is strong. During linking, a strong symbol can override a weak symbol of the same name. In contrast, in the presence of two strong symbols by the same name, the linker resolves the symbol in favor of the first one found. This behavior allows an executable to override standard library functions, such as malloc(3). When linking a binary executable, a weakly declared symbol does not need a definition. In comparison, a declared strong symbol without a definition triggers an undefined symbol link error.
Nemerle is a general-purpose, high-level, statically typed programming language designed for platforms using the Common Language Infrastructure (.NET/Mono). It offers functional, object-oriented, aspect-oriented, reflective and imperative features. It has a simple C#-like syntax and a powerful metaprogramming system.
Gcov is a source code coverage analysis and statement-by-statement profiling tool. Gcov generates exact counts of the number of times each statement in a program is executed and annotates source code to add instrumentation. Gcov comes as a standard utility with the GNU Compiler Collection (GCC) suite.
Objective-C is a high-level general-purpose, object-oriented programming language that adds Smalltalk-style message passing (messaging) to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXTSTEP operating system. Due to Apple macOS’s direct lineage from NeXTSTEP, Objective-C was the standard language used, supported, and promoted by Apple for developing macOS and iOS applications from 1997, when Apple purchased NeXT until the introduction of the Swift language in 2014.