[nm] command
nm
Name
nm - list symbols from object files
Synopsis
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] [-fformat│--format=format]
[--defined-only] [-l│--line-numbers] [--no-demangle]
[-V│--version] [-X 32_64] [--help] [objfile...]
Description
GNU nm lists the symbols from object files objfile.... If no object
files are listed as arguments, nm assumes the file a.out.
For each symbol, nm shows:
· The symbol value, in the radix selected by options (see below), or
hexadecimal by default.
· The symbol type. At least the following types are used; others
are, as well, depending on the object file format. If lowercase,
the symbol is local; if uppercase, the symbol is global (external).
"A" The symbol’s value is absolute, and will not be changed by fur‐
ther linking.
"B" The symbol is in the uninitialized data section (known as BSS).
"C" The symbol is common. Common symbols are uninitialized data.
When linking, multiple common symbols may appear with the same
name. If the symbol is defined anywhere, the common symbols
are treated as undefined references.
"D" The symbol is in the initialized data section.
"G" The symbol is in an initialized data section for small objects.
Some object file formats permit more efficient access to small
data objects, such as a global int variable as opposed to a
large global array.
"I" The symbol is an indirect reference to another symbol. This is
a GNU extension to the a.out object file format which is rarely
used.
"N" The symbol is a debugging symbol.
"R" The symbol is in a read only data section.
"S" The symbol is in an uninitialized data section for small
objects.
"T" The symbol is in the text (code) section.
"U" The symbol is undefined.
"V" The symbol is a weak object. When a weak defined symbol is
linked with a normal defined symbol, the normal defined symbol
is used with no error. When a weak undefined symbol is linked
and the symbol is not defined, the value of the weak symbol
becomes zero with no error.
"W" The symbol is a weak symbol that has not been specifically
tagged as a weak object symbol. When a weak defined symbol is
linked with a normal defined symbol, the normal defined symbol
is used with no error. When a weak undefined symbol is linked
and the symbol is not defined, the value of the symbol is
determined in a system-specific manner without 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.
· The symbol name.
nm은 라이브러리, 컴파일된 오브젝트 모듈, 공유 오브젝트 파일, 독립 실행파일등의 바이너리 파일을 검사해서 그 파일 들에 저장된 내용 또는 메타 정보를 표시한다. nm은 디버깅 과정에서 이름 겹침(naming conflict)과 C++ 이름 맹글링(naming mangling) 문제를 해결하거나 모듈의 심볼릭 정보를 확인하는데 사용된다.
nm의 출력은 크게 3개의 열로 되어 있다. 첫번째 열은 심볼 값을, 두번째 열은 심볼 타입을, 세번째 열은 심볼 이름을 나타낸다. 심볼 값은 생략 가능하고, 보통 table offset 값이나 virtual address를 나타낸다. 심볼 타입은 한 글자 알파벳으로 되어 있고, 심볼 이름은 말 그대로 이름을 나타낸다.
* naming mangling : compiler가 함수의 이름을 내부적인 규칙에 의거해서 바꾸는 것
Example
-
default
- dev@/home/dev/DEV/trunk/libsrc/SYSMON.R090/release:17 % nm tools.o
00000086 T SM_Get_LL_Match
000000b0 T SM_Get_Str_Match
00000000 T SM_Seek_Line
U atoll
U fgets
00000000 b line.3775
00001000 b match_string.3803
U strncmp
U strncpy
- dev@/home/dev/DEV/trunk/libsrc/SYSMON.R090/release:17 % nm tools.o
-
-l Option
- dev@/home/dev/DEV/trunk/libsrc/SYSMON.R090:25 % nm -l sysmon_r
0804c8c0 r C.0.3262
0804a8c0 T SM_Destroy_Process_Stat /home/dev/DEV/trunk/libsrc/SYSMON/process_stat.c:120
080494c1 T SM_Get_Cpu_Percent /home/dev/DEV/trunk/libsrc/SYSMON/cpu_stat.c:307
0804928a T SM_Get_Cpu_Percent_Diff /home/dev/DEV/trunk/libsrc/SYSMON/cpu_stat.c:252
08048fc8 T SM_Get_Cpu_Stat /home/dev/DEV/trunk/libsrc/SYSMON/cpu_stat.c:85
080490e1 T SM_Get_Cpu_Stat_Diff /home/dev/DEV/trunk/libsrc/SYSMON/cpu_stat.c:191
08049dce T SM_Get_Disk_Io_Stat /home/dev/DEV/trunk/libsrc/SYSMON/disk_stat.c:249
- dev@/home/dev/DEV/trunk/libsrc/SYSMON.R090:25 % nm -l sysmon_r
- naming conflict
- #include <stdio.h>
int fl(int a)
{
return 1;
}
int main(int argc, char** argv)
{
f1(1);
return 0;
}
dev@/home/dev/tmp:79 % gcc test.c
/tmp/ccVfreIk.o: In function `main':
test.c:(.text+0x23): undefined reference to `f1'
collect2: ld returned 1 exit status
dev@/home/dev/tmp:80 % gcc -c test.c
dev@/home/dev/tmp:81 % nm test.o
U f1
00000000 T fl
0000000a T main
이 글은 스프링노트에서 작성되었습니다.


