Explanation of symbol type in NM command

Source: Internet
Author: User

Excerpted from http://blog.csdn.net/solmyr_biti/article/details/6565479

The NM command introduces many, but mostly does not describe the meaning of its function symbol flags.
Most recently used in debugging a dynamic library, which uses the most:
Nm-a * |grep "AAA" | C++filt//-A in order to display the file, C++filt converted to a readable style, as if there is a parameter to achieve similar functions


Other content is organized as follows (unknown to the original author):

nm is used to list the symbol list of the target file , and the default is "A.out" if no target file is specified. The format of NM is as follows:

NM ['-A ' | ' --debug-syms '] ['-G ' | ' --extern-only ']
['-B '] ['-C ' | ' --demangle ' [=style]] ['-d ' | ' --dynamic ']
['-S ' | ' --print-size ' ['-s ' | ' --print-armap ']
['-A ' | ' -O ' | ' --print-file-name ' ['--special-syms ']
['-N ' | ' -V ' | ' --numeric-sort ' ['-P ' | ' --no-sort ']
['-R ' | ' --reverse-sort ' ['--size-sort '] ['-U ' | ' --undefined-only ']
['-t ' radix| ' --radix= ' radix] ['-P ' | ' --portability ']
['--target= ' bfdname] ['-F ' format| ' --format= ' format]
['--defined-only '] ['-L ' | ' --line-numbers '] ['--no-demangle ']
['-V ' | ' --version ' ['-X 32_64 '] ['--help '] [objfile ...]

for each symbol, NM lists its value (the symbol value), the type (the symbol type), and its name (the symbol name)。
The following example:

00000024 T Cleanup_before_linux
00000018 T Cpu_init
00000060 T dcache_disable
00000054 T dcache_enable
0000006c T Dcache_status
00000000 T Do_reset
0000003c T icache_disable
00000030 T icache_enable
00000048 T Icache_status

The above display is the output using NM CPU.O, for cleanup_before_linux this symbol, 00000024 is the value of the 16 binary display, T is its type, and Cleanup_before_linux is its name. As you can see, the value of the symbol shown above is actually the offset of the function in the text section of the Cleanup_before_linux. However, the specific meaning of each symbol's value varies depending on its type. Of course, for each symbol's value, its type, its value, and the section to which they belong are closely related.
The following is a description of the symbol type: For each symbol, the type if it is lowercase, indicates that the symbol is local, and uppercase indicates that the symbol is global (external).

Symbol
Type
Description
A The value of the symbol is absolute and is not allowed to be changed during subsequent links. Such symbolic values often appear in interrupt vector tables, such as symbols that represent the position of individual interrupt vector functions in the interrupt vector table.
B The value of the symbol appears in the non-initialized data segment (BSS). For example, define a global static int test in a file. The type of the symbol test is B and is in the BSS section. Its value represents the offset of the symbol in the BSS segment. Generally, BSS segments are allocated in RAM
C The symbol is common. Common symbol is an uninitialized session data segment. The symbol is not included in a common section. Allocations are only made during the link process. The value of the symbol represents the number of bytes required for the symbol. For example, in a C file, the int test is defined, and the symbol is referenced elsewhere, and the symbol type is C. Otherwise, its type is B.
D The symbol is in the initial session data segment. In general, it is assigned to the data section. For example, defining global int baud_table[5] = {9600, 19200, 38400, 57600, 115200} is assigned to the initialization data segment.
G The symbol is also in the initialization data segment. Used primarily for small object to improve access to small data object in one way.
I The symbol is an indirect reference to another symbol.
N The symbol is a debugging symbol.
R The symbol is located in the read-only data area. For example, define Global const int test[] = {123, 123}, then test is the symbol for a read-only data area. Note that the test in the source file corresponds to _test and its symbol type is D, which is initialized in the data segment, if Cygwin is compiled directly into MZ format using GCC. However, if you use a cross-compilation tool such as M6812-ELF-GCC, the test in the source file corresponds to the test of the target file, which is not underlined, and its symbol type is R. Generally, it is located in Rodata section. It is worth noting that if const char *test = "ABC" is defined in a function, const char Test_int = 3. No symbolic information is obtained using NM, but the string "ABC" is assigned to read-only memory, and test is in the Rodata section with a size of 4.
S The symbol is located in the non-initialized data area for small object.
T The symbol is located in the Code area text section.
U The symbol is undefined in the current file, meaning that the symbol is defined in another file. For example, the current file invokes a function defined in another file, where the called function is currently undefined, but the type in the file that defines it is t. But for global variables, in the file that defines it, the symbol type is C, and in the file that uses it, the type is U.
V The symbol is a weak object.
W The symbol is a weak symbol, the have not been specifically tagged as a weak object symbol.
- The symbol is stabs symbol in the a.out format file.
? The symbol type is not defined

Explanation of symbol type in NM command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.