strip经常用来去除目标文件中的一些符号表、调试符号表信息,以减小程序的大小,在rpmbuild包的最后就用到。
其支持的选项如下:
>strip -h
用法:strip <选项> 输入文件
从文件中删除符号和节
选项为:
-I --input-target=<bfdname> Assume input file is in format <bfdname>
-O --output-target=<bfdname> Create an output file in format <bfdname>
-F --target=<bfdname> Set both input and output format to <bfdname>
-p --preserve-dates Copy modified/access timestamps to the output
-R --remove-section=<name> Remove section <name> from the output
-s --strip-all Remove all symbol and relocation information
-g -S -d --strip-debug Remove all debugging symbols & sections
--strip-unneeded Remove all symbols not needed by relocations
--only-keep-debug Strip everything but the debug information
-N --strip-symbol=<name> Do not copy symbol <name>
-K --keep-symbol=<name> Do not strip symbol <name>
--keep-file-symbols Do not strip file symbol(s)
-w --wildcard Permit wildcard in symbol comparison
-x --discard-all Remove all non-global symbols
-X --discard-locals Remove any compiler-generated symbols
-v --verbose List all object files modified
-V --version Display this program's version number
-h --help Display this output
--info List object formats & architectures supported
-o <file> Place stripped output into <file>
strip: 支持的目标: elf32-i386 a.out-i386-linux efi-app-ia32 elf32-little elf32-big elf64-alpha ecoff-littlealpha elf64-little elf64-big elf32-littlearm elf32-bigarm elf32-hppa-linux elf32-hppa elf64-ia64-little elf64-ia64-big efi-app-ia64 elf32-m68k a.out-m68k-linux elf32-powerpc aixcoff-rs6000 elf32-powerpcle ppcboot elf64-powerpc elf64-powerpcle aixcoff64-rs6000 elf32-s390 elf64-s390 elf32-sparc a.out-sparc-linux elf64-sparc a.out-sunos-big elf64-x86-64 pe-i386 pei-i386 srec symbolsrec tekhex binary ihex trad-core
目标文件分为:可重定位文件、可执行文件、共享文件
strip的默认选项会去除.symbol节的内容以及.debug节的内容,因此尽量只对可执行文件执行strip而不要对静态库或动态库等目标文件strip。
测试代码如下:
>ar rcs libcmp.a max.o min.o
>gcc -o test main.c libcmp.a
>gcc -share -fPIC -o libcmp.so max.c min.c
>cp libcmp.a libcmp.a.bak
>cp libcmp.so libcmp.so.bak
>cp test test.orig
>strip libcmp.a libcmp.so
>strip test
>ll -h
总计 92K
-rwxr-xr-x 1 6.9K a.out
-rw-r--r-- 1 1.1K libcmp.a
-rw-r--r-- 1 1.6K libcmp.a.bak
-rwxr-xr-x 1 2.9K libcmp.so
-rwxr-xr-x 1 5.3K libcmp.so.bak
-rw-r--r-- 1 237 main.c
-rw-r--r-- 1 89 max.c
-rw-r--r-- 1 695 max.o
-rw-r--r-- 1 89 min.c
-rw-r--r-- 1 695 min.o
-rwxr-xr-x 1 3.2K test
-rwxr-xr-x 1 6.8K test.orig
选项简释:
The -fPIC flag directs the compiler to generate position independent code section).
The -shared flag directs the linker to create a shared object file.
可 见无论是静态库(libcmp.a)还是动态库(libcmp.so)还是可执行文件(test),去掉一些符号信息后都减小了很多,但如果这时再链接这 两个库的话是编不过的,因此,如果不是指定特殊的strip选项的话,还是尽量不要对库文件strip,只对链接后的可执行文件strip就可以了(如果 也不调试)。
>readelf -a test >1
>readelf -a test.orig >2
>cat 1
ELF 头:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (可执行文件)
Machine: Intel 80386
Version: 0x1
入口点地址: 0x8048350
程序头起点: 52 (bytes into file)
Start of section headers: 2196 (bytes into file)
标志: 0x0
本头的大小: 52 (字节)
程序头大小: 32 (字节)
程序头数量: 8
节头大小: 40 (字节)
节头数量: 27
字符串表索引节头: 26
节头:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 08048134 000134 000013 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 08048148 000148 000020 00 A 0 0 4
[ 3] .note.SuSE NOTE 08048168 000168 000018 00 A 0 0 4
[ 4] .hash HASH 08048180 000180 000030 04 A 5 0 4
[ 5] .dynsym DYNSYM 080481b0 0001b0 000070 10 A 6 1 4
[ 6] .dynstr STRTAB 08048220 000220 000066 00 A 0 0 1
[ 7] .gnu.version VERSYM 08048286 000286 00000e 02 A 5 0 2
[ 8] .gnu.version_r VERNEED 08048294 000294 000020 00 A 6 1 4
[ 9] .rel.dyn REL 080482b4 0002b4 000008 08 A 5 0 4
[10] .rel.plt REL 080482bc 0002bc 000020 08 A 5 12 4
[11] .init PROGBITS 080482dc 0002dc 000017 00 AX 0 0 4
[12] .plt PROGBITS 080482f4 0002f4 000050 04 AX 0 0 4
[13] .text PROGBITS 08048350 000350 00021c 00 AX 0 0 16
[14] .fini PROGBITS 0804856c 00056c 00001c 00 AX 0 0 4
[15] .rodata PROGBITS 08048588 000588 000013 00 A 0 0 4
[16] .eh_frame PROGBITS 0804859c 00059c 000004 00 A 0 0 4
[17] .ctors PROGBITS 080495a0 0005a0 000008 00 WA 0 0 4
[18] .dtors PROGBITS 080495a8 0005a8 000008 00 WA 0 0 4
[19] .jcr PROGBITS 080495b0 0005b0 000004 00 WA 0 0 4
[20] .dynamic DYNAMIC 080495b4 0005b4 0000c8 08 WA 6 0 4
[21] .got PROGBITS 0804967c 00067c 000004 04 WA 0 0 4
[22] .got.plt PROGBITS 08049680 000680 00001c 04 WA 0 0 4
[23] .data PROGBITS 0804969c 00069c 00000c 00 WA 0 0 4
[24] .bss NOBITS 080496a8 0006a8 000004 00 WA 0 0 4
[25] .comment PROGBITS 00000000 0006a8 000117 00 0 0 1
[26] .shstrtab STRTAB 00000000 0007bf 0000d2 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
程序头:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
INTERP 0x000134 0x08048134 0x08048134 0x00013 0x00013 R 0x1
[正在请求程序解释器:/lib/ld-linux.so.2]
LOAD 0x000000 0x08048000 0x08048000 0x005a0 0x005a0 R E 0x1000
LOAD 0x0005a0 0x080495a0 0x080495a0 0x00108 0x0010c RW 0x1000
DYNAMIC 0x0005b4 0x080495b4 0x080495b4 0x000c8 0x000c8 RW 0x4
NOTE 0x000148 0x08048148 0x08048148 0x00020 0x00020 R 0x4
NOTE 0x000168 0x08048168 0x08048168 0x00018 0x00018 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
Section to Segment mapping:
段节...
00
01 .interp
02 .interp .note.ABI-tag .note.SuSE .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame
03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.ABI-tag
06 .note.SuSE
07
Dynamic section at offset 0x5b4 contains 20 entries:
标记 类型 名称/值
0x00000001 (NEEDED) 共享库:[libc.so.6]
0x0000000c (INIT) 0x80482dc
0x0000000d (FINI) 0x804856c
0x00000004 (HASH) 0x8048180
0x00000005 (STRTAB) 0x8048220
0x00000006 (SYMTAB) 0x80481b0
0x0000000a (STRSZ) 102 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x8049680
0x00000002 (PLTRELSZ) 32 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x80482bc
0x00000011 (REL) 0x80482b4
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x8048294
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x8048286
0x00000000 (NULL) 0x0
重定位节 “.rel.dyn” 位于偏移量 0x2b4 含有 1 个条目:
Offset Info Type Sym.Value Sym. Name
0804967c 00000606 R_386_GLOB_DAT 00000000 __gmon_start__
重定位节 “.rel.plt” 位于偏移量 0x2bc 含有 4 个条目:
Offset Info Type Sym.Value Sym. Name
0804968c 00000107 R_386_JUMP_SLOT 00000000 scanf
08049690 00000207 R_386_JUMP_SLOT 00000000 __libc_start_main
08049694 00000307 R_386_JUMP_SLOT 00000000 printf
08049698 00000607 R_386_JUMP_SLOT 00000000 __gmon_start__
There are no unwind sections in this file.
Symbol table '.dynsym' contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 65 FUNC GLOBAL DEFAULT UND scanf@GLIBC_2.0 (2)
2: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)
3: 00000000 57 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)
4: 0804858c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used
5: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
6: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
Histogram for bucket list length (total of 3 buckets):
Length Number % of total Coverage
0 0 ( 0.0%)
1 0 ( 0.0%) 0.0%
2 3 (100.0%) 100.0%
版本符号节“.gnu.version”含有 7 个条目:
地址:0000000008048286 偏移量:0x000286 连接:5 (.dynsym)
000: 0 (*本地*) 2 (GLIBC_2.0) 2 (GLIBC_2.0) 2 (GLIBC_2.0)
004: 1 (*全局*) 0 (*本地*) 0 (*本地*)
Version needs section '.gnu.version_r' contains 1 entries:
地址:0x0000000008048294 Offset: 0x000294 Link to section: 6 (.dynstr)
000000: Version: 1 文件:libc.so.6 计数:1
0x0010: Name: GLIBC_2.0 标志:无 版本:2
注释位于偏移量 0x00000148 长度为 0x00000020:
所有者 数据大小 描述
GNU 0x00000010 NT_VERSION (version)
注释位于偏移量 0x00000168 长度为 0x00000018:
所有者 数据大小 描述
SuSE 0x00000004 未知的注释类型:(0x45537553)
>cat 2
ELF 头:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (可执行文件)
Machine: Intel 80386
Version: 0x1
入口点地址: 0x8048350
程序头起点: 52 (bytes into file)
Start of section headers: 3392 (bytes into file)
标志: 0x0
本头的大小: 52 (字节)
程序头大小: 32 (字节)
程序头数量: 8
节头大小: 40 (字节)
节头数量: 35
字符串表索引节头: 32
节头:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 08048134 000134 000013 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 08048148 000148 000020 00 A 0 0 4
[ 3] .note.SuSE NOTE 08048168 000168 000018 00 A 0 0 4
[ 4] .hash HASH 08048180 000180 000030 04 A 5 0 4
[ 5] .dynsym DYNSYM 080481b0 0001b0 000070 10 A 6 1 4
[ 6] .dynstr STRTAB 08048220 000220 000066 00 A 0 0 1
[ 7] .gnu.version VERSYM 08048286 000286 00000e 02 A 5 0 2
[ 8] .gnu.version_r VERNEED 08048294 000294 000020 00 A 6 1 4
[ 9] .rel.dyn REL 080482b4 0002b4 000008 08 A 5 0 4
[10] .rel.plt REL 080482bc 0002bc 000020 08 A 5 12 4
[11] .init PROGBITS 080482dc 0002dc 000017 00 AX 0 0 4
[12] .plt PROGBITS 080482f4 0002f4 000050 04 AX 0 0 4
[13] .text PROGBITS 08048350 000350 00021c 00 AX 0 0 16
[14] .fini PROGBITS 0804856c 00056c 00001c 00 AX 0 0 4
[15] .rodata PROGBITS 08048588 000588 000013 00 A 0 0 4
[16] .eh_frame PROGBITS 0804859c 00059c 000004 00 A 0 0 4
[17] .ctors PROGBITS 080495a0 0005a0 000008 00 WA 0 0 4
[18] .dtors PROGBITS 080495a8 0005a8 000008 00 WA 0 0 4
[19] .jcr PROGBITS 080495b0 0005b0 000004 00 WA 0 0 4
[20] .dynamic DYNAMIC 080495b4 0005b4 0000c8 08 WA 6 0 4
[21] .got PROGBITS 0804967c 00067c 000004 04 WA 0 0 4
[22] .got.plt PROGBITS 08049680 000680 00001c 04 WA 0 0 4
[23] .data PROGBITS 0804969c 00069c 00000c 00 WA 0 0 4
[24] .bss NOBITS 080496a8 0006a8 000004 00 WA 0 0 4
[25] .comment PROGBITS 00000000 0006a8 000117 00 0 0 1
[26] .debug_aranges PROGBITS 00000000 0007c0 000058 00 0 0 8
[27] .debug_pubnames PROGBITS 00000000 000818 000025 00 0 0 1
[28] .debug_info PROGBITS 00000000 00083d 000191 00 0 0 1
[29] .debug_abbrev PROGBITS 00000000 0009ce 000062 00 0 0 1
[30] .debug_line PROGBITS 00000000 000a30 000137 00 0 0 1
[31] .debug_str PROGBITS 00000000 000b67 0000a5 01 MS 0 0 1
[32] .shstrtab STRTAB 00000000 000c0c 000132 00 0 0 1
[33] .symtab SYMTAB 00000000 0012b8 000570 10 34 65 4
[34] .strtab STRTAB 00000000 001828 0002d9 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
程序头:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
INTERP 0x000134 0x08048134 0x08048134 0x00013 0x00013 R 0x1
[正在请求程序解释器:/lib/ld-linux.so.2]
LOAD 0x000000 0x08048000 0x08048000 0x005a0 0x005a0 R E 0x1000
LOAD 0x0005a0 0x080495a0 0x080495a0 0x00108 0x0010c RW 0x1000
DYNAMIC 0x0005b4 0x080495b4 0x080495b4 0x000c8 0x000c8 RW 0x4
NOTE 0x000148 0x08048148 0x08048148 0x00020 0x00020 R 0x4
NOTE 0x000168 0x08048168 0x08048168 0x00018 0x00018 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
Section to Segment mapping:
段节...
00
01 .interp
02 .interp .note.ABI-tag .note.SuSE .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame
03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.ABI-tag
06 .note.SuSE
07
Dynamic section at offset 0x5b4 contains 20 entries:
标记 类型 名称/值
0x00000001 (NEEDED) 共享库:[libc.so.6]
0x0000000c (INIT) 0x80482dc
0x0000000d (FINI) 0x804856c
0x00000004 (HASH) 0x8048180
0x00000005 (STRTAB) 0x8048220
0x00000006 (SYMTAB) 0x80481b0
0x0000000a (STRSZ) 102 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x8049680
0x00000002 (PLTRELSZ) 32 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x80482bc
0x00000011 (REL) 0x80482b4
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x8048294
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x8048286
0x00000000 (NULL) 0x0
重定位节 “.rel.dyn” 位于偏移量 0x2b4 含有 1 个条目:
Offset Info Type Sym.Value Sym. Name
0804967c 00000606 R_386_GLOB_DAT 00000000 __gmon_start__
重定位节 “.rel.plt” 位于偏移量 0x2bc 含有 4 个条目:
Offset Info Type Sym.Value Sym. Name
0804968c 00000107 R_386_JUMP_SLOT 00000000 scanf
08049690 00000207 R_386_JUMP_SLOT 00000000 __libc_start_main
08049694 00000307 R_386_JUMP_SLOT 00000000 printf
08049698 00000607 R_386_JUMP_SLOT 00000000 __gmon_start__
There are no unwind sections in this file.
Symbol table '.dynsym' contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 65 FUNC GLOBAL DEFAULT UND scanf@GLIBC_2.0 (2)
2: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)
3: 00000000 57 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)
4: 0804858c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used
5: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
6: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
Symbol table '.symtab' contains 87 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 08048134 0 SECTION LOCAL DEFAULT 1
2: 08048148 0 SECTION LOCAL DEFAULT 2
3: 08048168 0 SECTION LOCAL DEFAULT 3
4: 08048180 0 SECTION LOCAL DEFAULT 4
5: 080481b0 0 SECTION LOCAL DEFAULT 5
6: 08048220 0 SECTION LOCAL DEFAULT 6
7: 08048286 0 SECTION LOCAL DEFAULT 7
8: 08048294 0 SECTION LOCAL DEFAULT 8
9: 080482b4 0 SECTION LOCAL DEFAULT 9
10: 080482bc 0 SECTION LOCAL DEFAULT 10
11: 080482dc 0 SECTION LOCAL DEFAULT 11
12: 080482f4 0 SECTION LOCAL DEFAULT 12
13: 08048350 0 SECTION LOCAL DEFAULT 13
14: 0804856c 0 SECTION LOCAL DEFAULT 14
15: 08048588 0 SECTION LOCAL DEFAULT 15
16: 0804859c 0 SECTION LOCAL DEFAULT 16
17: 080495a0 0 SECTION LOCAL DEFAULT 17
18: 080495a8 0 SECTION LOCAL DEFAULT 18
19: 080495b0 0 SECTION LOCAL DEFAULT 19
20: 080495b4 0 SECTION LOCAL DEFAULT 20
21: 0804967c 0 SECTION LOCAL DEFAULT 21
22: 08049680 0 SECTION LOCAL DEFAULT 22
23: 0804969c 0 SECTION LOCAL DEFAULT 23
24: 080496a8 0 SECTION LOCAL DEFAULT 24
25: 00000000 0 SECTION LOCAL DEFAULT 25
26: 00000000 0 SECTION LOCAL DEFAULT 26
27: 00000000 0 SECTION LOCAL DEFAULT 27
28: 00000000 0 SECTION LOCAL DEFAULT 28
29: 00000000 0 SECTION LOCAL DEFAULT 29
30: 00000000 0 SECTION LOCAL DEFAULT 30
31: 00000000 0 SECTION LOCAL DEFAULT 31
32: 00000000 0 SECTION LOCAL DEFAULT 32
33: 00000000 0 SECTION LOCAL DEFAULT 33
34: 00000000 0 SECTION LOCAL DEFAULT 34
35: 00000000 0 FILE LOCAL DEFAULT ABS abi-note.S
36: 00000000 0 FILE LOCAL DEFAULT ABS suse-note.S
37: 00000000 0 FILE LOCAL DEFAULT ABS ../sysdeps/i386/elf/start
38: 00000000 0 FILE LOCAL DEFAULT ABS init.c
39: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c
40: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/packages/BUILD/g
41: 08048374 0 FUNC LOCAL DEFAULT 13 call_gmon_start
42: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
43: 080495a0 0 OBJECT LOCAL DEFAULT 17 __CTOR_LIST__
44: 080495a8 0 OBJECT LOCAL DEFAULT 18 __DTOR_LIST__
45: 080495b0 0 OBJECT LOCAL DEFAULT 19 __JCR_LIST__
46: 080496a8 1 OBJECT LOCAL DEFAULT 24 completed.5751
47: 080496a4 0 OBJECT LOCAL DEFAULT 23 p.5749
48: 080483a0 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux
49: 080483d0 0 FUNC LOCAL DEFAULT 13 frame_dummy
50: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
51: 080495a4 0 OBJECT LOCAL DEFAULT 17 __CTOR_END__
52: 080495ac 0 OBJECT LOCAL DEFAULT 18 __DTOR_END__
53: 0804859c 0 OBJECT LOCAL DEFAULT 16 __FRAME_END__
54: 080495b0 0 OBJECT LOCAL DEFAULT 19 __JCR_END__
55: 08048540 0 FUNC LOCAL DEFAULT 13 __do_global_ctors_aux
56: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c
57: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/packages/BUILD/g
58: 00000000 0 FILE LOCAL DEFAULT ABS main.c
59: 00000000 0 FILE LOCAL DEFAULT ABS max.c
60: 00000000 0 FILE LOCAL DEFAULT ABS min.c
61: 080495b4 0 OBJECT LOCAL HIDDEN 20 _DYNAMIC
62: 080495a0 0 NOTYPE LOCAL HIDDEN ABS __init_array_end
63: 08049680 0 OBJECT LOCAL HIDDEN 22 _GLOBAL_OFFSET_TABLE_
64: 080495a0 0 NOTYPE LOCAL HIDDEN ABS __init_array_start
65: 08048588 4 OBJECT GLOBAL DEFAULT 15 _fp_hw
66: 080496a0 0 OBJECT GLOBAL HIDDEN 23 __dso_handle
67: 080484d0 5 FUNC GLOBAL DEFAULT 13 __libc_csu_fini
68: 080482dc 0 FUNC GLOBAL DEFAULT 11 _init
69: 00000000 65 FUNC GLOBAL DEFAULT UND scanf@@GLIBC_2.0
70: 08048350 0 FUNC GLOBAL DEFAULT 13 _start
71: 0804846c 43 FUNC GLOBAL DEFAULT 13 max
72: 080484e0 92 FUNC GLOBAL DEFAULT 13 __libc_csu_init
73: 080496a8 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
74: 080483f4 120 FUNC GLOBAL DEFAULT 13 main
75: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
76: 0804969c 0 NOTYPE WEAK DEFAULT 23 data_start
77: 08048498 43 FUNC GLOBAL DEFAULT 13 min
78: 00000000 57 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.0
79: 0804856c 0 FUNC GLOBAL DEFAULT 14 _fini
80: 080496a8 0 NOTYPE GLOBAL DEFAULT ABS _edata
81: 0804853c 0 FUNC GLOBAL HIDDEN 13 __i686.get_pc_thunk.bx
82: 080496ac 0 NOTYPE GLOBAL DEFAULT ABS _end
83: 0804858c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used
84: 0804969c 0 NOTYPE GLOBAL DEFAULT 23 __data_start
85: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
86: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
Histogram for bucket list length (total of 3 buckets):
Length Number % of total Coverage
0 0 ( 0.0%)
1 0 ( 0.0%) 0.0%
2 3 (100.0%) 100.0%
版本符号节“.gnu.version”含有 7 个条目:
地址:0000000008048286 偏移量:0x000286 连接:5 (.dynsym)
000: 0 (*本地*) 2 (GLIBC_2.0) 2 (GLIBC_2.0) 2 (GLIBC_2.0)
004: 1 (*全局*) 0 (*本地*) 0 (*本地*)
Version needs section '.gnu.version_r' contains 1 entries:
地址:0x0000000008048294 Offset: 0x000294 Link to section: 6 (.dynstr)
000000: Version: 1 文件:libc.so.6 计数:1
0x0010: Name: GLIBC_2.0 标志:无 版本:2
注释位于偏移量 0x00000148 长度为 0x00000020:
所有者 数据大小 描述
GNU 0x00000010 NT_VERSION (version)
注释位于偏移量 0x00000168 长度为 0x00000018:
所有者 数据大小 描述
SuSE 0x00000004 未知的注释类型:(0x45537553)
>diff -Nur 1 2 >3.patch
>vi 3.patch
其支持的选项如下:
>strip -h
用法:strip <选项> 输入文件
从文件中删除符号和节
选项为:
-I --input-target=<bfdname> Assume input file is in format <bfdname>
-O --output-target=<bfdname> Create an output file in format <bfdname>
-F --target=<bfdname> Set both input and output format to <bfdname>
-p --preserve-dates Copy modified/access timestamps to the output
-R --remove-section=<name> Remove section <name> from the output
-s --strip-all Remove all symbol and relocation information
-g -S -d --strip-debug Remove all debugging symbols & sections
--strip-unneeded Remove all symbols not needed by relocations
--only-keep-debug Strip everything but the debug information
-N --strip-symbol=<name> Do not copy symbol <name>
-K --keep-symbol=<name> Do not strip symbol <name>
--keep-file-symbols Do not strip file symbol(s)
-w --wildcard Permit wildcard in symbol comparison
-x --discard-all Remove all non-global symbols
-X --discard-locals Remove any compiler-generated symbols
-v --verbose List all object files modified
-V --version Display this program's version number
-h --help Display this output
--info List object formats & architectures supported
-o <file> Place stripped output into <file>
strip: 支持的目标: elf32-i386 a.out-i386-linux efi-app-ia32 elf32-little elf32-big elf64-alpha ecoff-littlealpha elf64-little elf64-big elf32-littlearm elf32-bigarm elf32-hppa-linux elf32-hppa elf64-ia64-little elf64-ia64-big efi-app-ia64 elf32-m68k a.out-m68k-linux elf32-powerpc aixcoff-rs6000 elf32-powerpcle ppcboot elf64-powerpc elf64-powerpcle aixcoff64-rs6000 elf32-s390 elf64-s390 elf32-sparc a.out-sparc-linux elf64-sparc a.out-sunos-big elf64-x86-64 pe-i386 pei-i386 srec symbolsrec tekhex binary ihex trad-core
目标文件分为:可重定位文件、可执行文件、共享文件
strip的默认选项会去除.symbol节的内容以及.debug节的内容,因此尽量只对可执行文件执行strip而不要对静态库或动态库等目标文件strip。
测试代码如下:
/* max.c */
int max(int val1, int val2)
{
int iVal = (val1 > val2) ? val1 : val2;
return iVal;
}
/* min.c */
int min(int val1, int val2)
{
int iVal = (val1 < val2) ? val1 : val2;
return iVal;
}
/* main.c */>gcc -c max.c min.c
#include <stdio.h>
extern int max(int val1, int val2);
extern int min(int val1, int val2);
int main()
{
int val1, val2;
scanf("%d %d", &val1, &val2);
printf("%d/n", max(val1, val2));
printf("%d/n", min(val1, val2));
}
>ar rcs libcmp.a max.o min.o
>gcc -o test main.c libcmp.a
>gcc -share -fPIC -o libcmp.so max.c min.c
>cp libcmp.a libcmp.a.bak
>cp libcmp.so libcmp.so.bak
>cp test test.orig
>strip libcmp.a libcmp.so
>strip test
>ll -h
总计 92K
-rwxr-xr-x 1 6.9K a.out
-rw-r--r-- 1 1.1K libcmp.a
-rw-r--r-- 1 1.6K libcmp.a.bak
-rwxr-xr-x 1 2.9K libcmp.so
-rwxr-xr-x 1 5.3K libcmp.so.bak
-rw-r--r-- 1 237 main.c
-rw-r--r-- 1 89 max.c
-rw-r--r-- 1 695 max.o
-rw-r--r-- 1 89 min.c
-rw-r--r-- 1 695 min.o
-rwxr-xr-x 1 3.2K test
-rwxr-xr-x 1 6.8K test.orig
选项简释:
The -fPIC flag directs the compiler to generate position independent code section).
The -shared flag directs the linker to create a shared object file.
可 见无论是静态库(libcmp.a)还是动态库(libcmp.so)还是可执行文件(test),去掉一些符号信息后都减小了很多,但如果这时再链接这 两个库的话是编不过的,因此,如果不是指定特殊的strip选项的话,还是尽量不要对库文件strip,只对链接后的可执行文件strip就可以了(如果 也不调试)。
>readelf -a test >1
>readelf -a test.orig >2
>cat 1
ELF 头:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (可执行文件)
Machine: Intel 80386
Version: 0x1
入口点地址: 0x8048350
程序头起点: 52 (bytes into file)
Start of section headers: 2196 (bytes into file)
标志: 0x0
本头的大小: 52 (字节)
程序头大小: 32 (字节)
程序头数量: 8
节头大小: 40 (字节)
节头数量: 27
字符串表索引节头: 26
节头:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 08048134 000134 000013 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 08048148 000148 000020 00 A 0 0 4
[ 3] .note.SuSE NOTE 08048168 000168 000018 00 A 0 0 4
[ 4] .hash HASH 08048180 000180 000030 04 A 5 0 4
[ 5] .dynsym DYNSYM 080481b0 0001b0 000070 10 A 6 1 4
[ 6] .dynstr STRTAB 08048220 000220 000066 00 A 0 0 1
[ 7] .gnu.version VERSYM 08048286 000286 00000e 02 A 5 0 2
[ 8] .gnu.version_r VERNEED 08048294 000294 000020 00 A 6 1 4
[ 9] .rel.dyn REL 080482b4 0002b4 000008 08 A 5 0 4
[10] .rel.plt REL 080482bc 0002bc 000020 08 A 5 12 4
[11] .init PROGBITS 080482dc 0002dc 000017 00 AX 0 0 4
[12] .plt PROGBITS 080482f4 0002f4 000050 04 AX 0 0 4
[13] .text PROGBITS 08048350 000350 00021c 00 AX 0 0 16
[14] .fini PROGBITS 0804856c 00056c 00001c 00 AX 0 0 4
[15] .rodata PROGBITS 08048588 000588 000013 00 A 0 0 4
[16] .eh_frame PROGBITS 0804859c 00059c 000004 00 A 0 0 4
[17] .ctors PROGBITS 080495a0 0005a0 000008 00 WA 0 0 4
[18] .dtors PROGBITS 080495a8 0005a8 000008 00 WA 0 0 4
[19] .jcr PROGBITS 080495b0 0005b0 000004 00 WA 0 0 4
[20] .dynamic DYNAMIC 080495b4 0005b4 0000c8 08 WA 6 0 4
[21] .got PROGBITS 0804967c 00067c 000004 04 WA 0 0 4
[22] .got.plt PROGBITS 08049680 000680 00001c 04 WA 0 0 4
[23] .data PROGBITS 0804969c 00069c 00000c 00 WA 0 0 4
[24] .bss NOBITS 080496a8 0006a8 000004 00 WA 0 0 4
[25] .comment PROGBITS 00000000 0006a8 000117 00 0 0 1
[26] .shstrtab STRTAB 00000000 0007bf 0000d2 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
程序头:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
INTERP 0x000134 0x08048134 0x08048134 0x00013 0x00013 R 0x1
[正在请求程序解释器:/lib/ld-linux.so.2]
LOAD 0x000000 0x08048000 0x08048000 0x005a0 0x005a0 R E 0x1000
LOAD 0x0005a0 0x080495a0 0x080495a0 0x00108 0x0010c RW 0x1000
DYNAMIC 0x0005b4 0x080495b4 0x080495b4 0x000c8 0x000c8 RW 0x4
NOTE 0x000148 0x08048148 0x08048148 0x00020 0x00020 R 0x4
NOTE 0x000168 0x08048168 0x08048168 0x00018 0x00018 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
Section to Segment mapping:
段节...
00
01 .interp
02 .interp .note.ABI-tag .note.SuSE .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame
03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.ABI-tag
06 .note.SuSE
07
Dynamic section at offset 0x5b4 contains 20 entries:
标记 类型 名称/值
0x00000001 (NEEDED) 共享库:[libc.so.6]
0x0000000c (INIT) 0x80482dc
0x0000000d (FINI) 0x804856c
0x00000004 (HASH) 0x8048180
0x00000005 (STRTAB) 0x8048220
0x00000006 (SYMTAB) 0x80481b0
0x0000000a (STRSZ) 102 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x8049680
0x00000002 (PLTRELSZ) 32 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x80482bc
0x00000011 (REL) 0x80482b4
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x8048294
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x8048286
0x00000000 (NULL) 0x0
重定位节 “.rel.dyn” 位于偏移量 0x2b4 含有 1 个条目:
Offset Info Type Sym.Value Sym. Name
0804967c 00000606 R_386_GLOB_DAT 00000000 __gmon_start__
重定位节 “.rel.plt” 位于偏移量 0x2bc 含有 4 个条目:
Offset Info Type Sym.Value Sym. Name
0804968c 00000107 R_386_JUMP_SLOT 00000000 scanf
08049690 00000207 R_386_JUMP_SLOT 00000000 __libc_start_main
08049694 00000307 R_386_JUMP_SLOT 00000000 printf
08049698 00000607 R_386_JUMP_SLOT 00000000 __gmon_start__
There are no unwind sections in this file.
Symbol table '.dynsym' contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 65 FUNC GLOBAL DEFAULT UND scanf@GLIBC_2.0 (2)
2: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)
3: 00000000 57 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)
4: 0804858c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used
5: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
6: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
Histogram for bucket list length (total of 3 buckets):
Length Number % of total Coverage
0 0 ( 0.0%)
1 0 ( 0.0%) 0.0%
2 3 (100.0%) 100.0%
版本符号节“.gnu.version”含有 7 个条目:
地址:0000000008048286 偏移量:0x000286 连接:5 (.dynsym)
000: 0 (*本地*) 2 (GLIBC_2.0) 2 (GLIBC_2.0) 2 (GLIBC_2.0)
004: 1 (*全局*) 0 (*本地*) 0 (*本地*)
Version needs section '.gnu.version_r' contains 1 entries:
地址:0x0000000008048294 Offset: 0x000294 Link to section: 6 (.dynstr)
000000: Version: 1 文件:libc.so.6 计数:1
0x0010: Name: GLIBC_2.0 标志:无 版本:2
注释位于偏移量 0x00000148 长度为 0x00000020:
所有者 数据大小 描述
GNU 0x00000010 NT_VERSION (version)
注释位于偏移量 0x00000168 长度为 0x00000018:
所有者 数据大小 描述
SuSE 0x00000004 未知的注释类型:(0x45537553)
>cat 2
ELF 头:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (可执行文件)
Machine: Intel 80386
Version: 0x1
入口点地址: 0x8048350
程序头起点: 52 (bytes into file)
Start of section headers: 3392 (bytes into file)
标志: 0x0
本头的大小: 52 (字节)
程序头大小: 32 (字节)
程序头数量: 8
节头大小: 40 (字节)
节头数量: 35
字符串表索引节头: 32
节头:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 08048134 000134 000013 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 08048148 000148 000020 00 A 0 0 4
[ 3] .note.SuSE NOTE 08048168 000168 000018 00 A 0 0 4
[ 4] .hash HASH 08048180 000180 000030 04 A 5 0 4
[ 5] .dynsym DYNSYM 080481b0 0001b0 000070 10 A 6 1 4
[ 6] .dynstr STRTAB 08048220 000220 000066 00 A 0 0 1
[ 7] .gnu.version VERSYM 08048286 000286 00000e 02 A 5 0 2
[ 8] .gnu.version_r VERNEED 08048294 000294 000020 00 A 6 1 4
[ 9] .rel.dyn REL 080482b4 0002b4 000008 08 A 5 0 4
[10] .rel.plt REL 080482bc 0002bc 000020 08 A 5 12 4
[11] .init PROGBITS 080482dc 0002dc 000017 00 AX 0 0 4
[12] .plt PROGBITS 080482f4 0002f4 000050 04 AX 0 0 4
[13] .text PROGBITS 08048350 000350 00021c 00 AX 0 0 16
[14] .fini PROGBITS 0804856c 00056c 00001c 00 AX 0 0 4
[15] .rodata PROGBITS 08048588 000588 000013 00 A 0 0 4
[16] .eh_frame PROGBITS 0804859c 00059c 000004 00 A 0 0 4
[17] .ctors PROGBITS 080495a0 0005a0 000008 00 WA 0 0 4
[18] .dtors PROGBITS 080495a8 0005a8 000008 00 WA 0 0 4
[19] .jcr PROGBITS 080495b0 0005b0 000004 00 WA 0 0 4
[20] .dynamic DYNAMIC 080495b4 0005b4 0000c8 08 WA 6 0 4
[21] .got PROGBITS 0804967c 00067c 000004 04 WA 0 0 4
[22] .got.plt PROGBITS 08049680 000680 00001c 04 WA 0 0 4
[23] .data PROGBITS 0804969c 00069c 00000c 00 WA 0 0 4
[24] .bss NOBITS 080496a8 0006a8 000004 00 WA 0 0 4
[25] .comment PROGBITS 00000000 0006a8 000117 00 0 0 1
[26] .debug_aranges PROGBITS 00000000 0007c0 000058 00 0 0 8
[27] .debug_pubnames PROGBITS 00000000 000818 000025 00 0 0 1
[28] .debug_info PROGBITS 00000000 00083d 000191 00 0 0 1
[29] .debug_abbrev PROGBITS 00000000 0009ce 000062 00 0 0 1
[30] .debug_line PROGBITS 00000000 000a30 000137 00 0 0 1
[31] .debug_str PROGBITS 00000000 000b67 0000a5 01 MS 0 0 1
[32] .shstrtab STRTAB 00000000 000c0c 000132 00 0 0 1
[33] .symtab SYMTAB 00000000 0012b8 000570 10 34 65 4
[34] .strtab STRTAB 00000000 001828 0002d9 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings)
I (info), L (link order), G (group), x (unknown)
O (extra OS processing required) o (OS specific), p (processor specific)
There are no section groups in this file.
程序头:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000034 0x08048034 0x08048034 0x00100 0x00100 R E 0x4
INTERP 0x000134 0x08048134 0x08048134 0x00013 0x00013 R 0x1
[正在请求程序解释器:/lib/ld-linux.so.2]
LOAD 0x000000 0x08048000 0x08048000 0x005a0 0x005a0 R E 0x1000
LOAD 0x0005a0 0x080495a0 0x080495a0 0x00108 0x0010c RW 0x1000
DYNAMIC 0x0005b4 0x080495b4 0x080495b4 0x000c8 0x000c8 RW 0x4
NOTE 0x000148 0x08048148 0x08048148 0x00020 0x00020 R 0x4
NOTE 0x000168 0x08048168 0x08048168 0x00018 0x00018 R 0x4
GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4
Section to Segment mapping:
段节...
00
01 .interp
02 .interp .note.ABI-tag .note.SuSE .hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame
03 .ctors .dtors .jcr .dynamic .got .got.plt .data .bss
04 .dynamic
05 .note.ABI-tag
06 .note.SuSE
07
Dynamic section at offset 0x5b4 contains 20 entries:
标记 类型 名称/值
0x00000001 (NEEDED) 共享库:[libc.so.6]
0x0000000c (INIT) 0x80482dc
0x0000000d (FINI) 0x804856c
0x00000004 (HASH) 0x8048180
0x00000005 (STRTAB) 0x8048220
0x00000006 (SYMTAB) 0x80481b0
0x0000000a (STRSZ) 102 (bytes)
0x0000000b (SYMENT) 16 (bytes)
0x00000015 (DEBUG) 0x0
0x00000003 (PLTGOT) 0x8049680
0x00000002 (PLTRELSZ) 32 (bytes)
0x00000014 (PLTREL) REL
0x00000017 (JMPREL) 0x80482bc
0x00000011 (REL) 0x80482b4
0x00000012 (RELSZ) 8 (bytes)
0x00000013 (RELENT) 8 (bytes)
0x6ffffffe (VERNEED) 0x8048294
0x6fffffff (VERNEEDNUM) 1
0x6ffffff0 (VERSYM) 0x8048286
0x00000000 (NULL) 0x0
重定位节 “.rel.dyn” 位于偏移量 0x2b4 含有 1 个条目:
Offset Info Type Sym.Value Sym. Name
0804967c 00000606 R_386_GLOB_DAT 00000000 __gmon_start__
重定位节 “.rel.plt” 位于偏移量 0x2bc 含有 4 个条目:
Offset Info Type Sym.Value Sym. Name
0804968c 00000107 R_386_JUMP_SLOT 00000000 scanf
08049690 00000207 R_386_JUMP_SLOT 00000000 __libc_start_main
08049694 00000307 R_386_JUMP_SLOT 00000000 printf
08049698 00000607 R_386_JUMP_SLOT 00000000 __gmon_start__
There are no unwind sections in this file.
Symbol table '.dynsym' contains 7 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 65 FUNC GLOBAL DEFAULT UND scanf@GLIBC_2.0 (2)
2: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@GLIBC_2.0 (2)
3: 00000000 57 FUNC GLOBAL DEFAULT UND printf@GLIBC_2.0 (2)
4: 0804858c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used
5: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
6: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
Symbol table '.symtab' contains 87 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 08048134 0 SECTION LOCAL DEFAULT 1
2: 08048148 0 SECTION LOCAL DEFAULT 2
3: 08048168 0 SECTION LOCAL DEFAULT 3
4: 08048180 0 SECTION LOCAL DEFAULT 4
5: 080481b0 0 SECTION LOCAL DEFAULT 5
6: 08048220 0 SECTION LOCAL DEFAULT 6
7: 08048286 0 SECTION LOCAL DEFAULT 7
8: 08048294 0 SECTION LOCAL DEFAULT 8
9: 080482b4 0 SECTION LOCAL DEFAULT 9
10: 080482bc 0 SECTION LOCAL DEFAULT 10
11: 080482dc 0 SECTION LOCAL DEFAULT 11
12: 080482f4 0 SECTION LOCAL DEFAULT 12
13: 08048350 0 SECTION LOCAL DEFAULT 13
14: 0804856c 0 SECTION LOCAL DEFAULT 14
15: 08048588 0 SECTION LOCAL DEFAULT 15
16: 0804859c 0 SECTION LOCAL DEFAULT 16
17: 080495a0 0 SECTION LOCAL DEFAULT 17
18: 080495a8 0 SECTION LOCAL DEFAULT 18
19: 080495b0 0 SECTION LOCAL DEFAULT 19
20: 080495b4 0 SECTION LOCAL DEFAULT 20
21: 0804967c 0 SECTION LOCAL DEFAULT 21
22: 08049680 0 SECTION LOCAL DEFAULT 22
23: 0804969c 0 SECTION LOCAL DEFAULT 23
24: 080496a8 0 SECTION LOCAL DEFAULT 24
25: 00000000 0 SECTION LOCAL DEFAULT 25
26: 00000000 0 SECTION LOCAL DEFAULT 26
27: 00000000 0 SECTION LOCAL DEFAULT 27
28: 00000000 0 SECTION LOCAL DEFAULT 28
29: 00000000 0 SECTION LOCAL DEFAULT 29
30: 00000000 0 SECTION LOCAL DEFAULT 30
31: 00000000 0 SECTION LOCAL DEFAULT 31
32: 00000000 0 SECTION LOCAL DEFAULT 32
33: 00000000 0 SECTION LOCAL DEFAULT 33
34: 00000000 0 SECTION LOCAL DEFAULT 34
35: 00000000 0 FILE LOCAL DEFAULT ABS abi-note.S
36: 00000000 0 FILE LOCAL DEFAULT ABS suse-note.S
37: 00000000 0 FILE LOCAL DEFAULT ABS ../sysdeps/i386/elf/start
38: 00000000 0 FILE LOCAL DEFAULT ABS init.c
39: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c
40: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/packages/BUILD/g
41: 08048374 0 FUNC LOCAL DEFAULT 13 call_gmon_start
42: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
43: 080495a0 0 OBJECT LOCAL DEFAULT 17 __CTOR_LIST__
44: 080495a8 0 OBJECT LOCAL DEFAULT 18 __DTOR_LIST__
45: 080495b0 0 OBJECT LOCAL DEFAULT 19 __JCR_LIST__
46: 080496a8 1 OBJECT LOCAL DEFAULT 24 completed.5751
47: 080496a4 0 OBJECT LOCAL DEFAULT 23 p.5749
48: 080483a0 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux
49: 080483d0 0 FUNC LOCAL DEFAULT 13 frame_dummy
50: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
51: 080495a4 0 OBJECT LOCAL DEFAULT 17 __CTOR_END__
52: 080495ac 0 OBJECT LOCAL DEFAULT 18 __DTOR_END__
53: 0804859c 0 OBJECT LOCAL DEFAULT 16 __FRAME_END__
54: 080495b0 0 OBJECT LOCAL DEFAULT 19 __JCR_END__
55: 08048540 0 FUNC LOCAL DEFAULT 13 __do_global_ctors_aux
56: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c
57: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/packages/BUILD/g
58: 00000000 0 FILE LOCAL DEFAULT ABS main.c
59: 00000000 0 FILE LOCAL DEFAULT ABS max.c
60: 00000000 0 FILE LOCAL DEFAULT ABS min.c
61: 080495b4 0 OBJECT LOCAL HIDDEN 20 _DYNAMIC
62: 080495a0 0 NOTYPE LOCAL HIDDEN ABS __init_array_end
63: 08049680 0 OBJECT LOCAL HIDDEN 22 _GLOBAL_OFFSET_TABLE_
64: 080495a0 0 NOTYPE LOCAL HIDDEN ABS __init_array_start
65: 08048588 4 OBJECT GLOBAL DEFAULT 15 _fp_hw
66: 080496a0 0 OBJECT GLOBAL HIDDEN 23 __dso_handle
67: 080484d0 5 FUNC GLOBAL DEFAULT 13 __libc_csu_fini
68: 080482dc 0 FUNC GLOBAL DEFAULT 11 _init
69: 00000000 65 FUNC GLOBAL DEFAULT UND scanf@@GLIBC_2.0
70: 08048350 0 FUNC GLOBAL DEFAULT 13 _start
71: 0804846c 43 FUNC GLOBAL DEFAULT 13 max
72: 080484e0 92 FUNC GLOBAL DEFAULT 13 __libc_csu_init
73: 080496a8 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
74: 080483f4 120 FUNC GLOBAL DEFAULT 13 main
75: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
76: 0804969c 0 NOTYPE WEAK DEFAULT 23 data_start
77: 08048498 43 FUNC GLOBAL DEFAULT 13 min
78: 00000000 57 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.0
79: 0804856c 0 FUNC GLOBAL DEFAULT 14 _fini
80: 080496a8 0 NOTYPE GLOBAL DEFAULT ABS _edata
81: 0804853c 0 FUNC GLOBAL HIDDEN 13 __i686.get_pc_thunk.bx
82: 080496ac 0 NOTYPE GLOBAL DEFAULT ABS _end
83: 0804858c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used
84: 0804969c 0 NOTYPE GLOBAL DEFAULT 23 __data_start
85: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
86: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
Histogram for bucket list length (total of 3 buckets):
Length Number % of total Coverage
0 0 ( 0.0%)
1 0 ( 0.0%) 0.0%
2 3 (100.0%) 100.0%
版本符号节“.gnu.version”含有 7 个条目:
地址:0000000008048286 偏移量:0x000286 连接:5 (.dynsym)
000: 0 (*本地*) 2 (GLIBC_2.0) 2 (GLIBC_2.0) 2 (GLIBC_2.0)
004: 1 (*全局*) 0 (*本地*) 0 (*本地*)
Version needs section '.gnu.version_r' contains 1 entries:
地址:0x0000000008048294 Offset: 0x000294 Link to section: 6 (.dynstr)
000000: Version: 1 文件:libc.so.6 计数:1
0x0010: Name: GLIBC_2.0 标志:无 版本:2
注释位于偏移量 0x00000148 长度为 0x00000020:
所有者 数据大小 描述
GNU 0x00000010 NT_VERSION (version)
注释位于偏移量 0x00000168 长度为 0x00000018:
所有者 数据大小 描述
SuSE 0x00000004 未知的注释类型:(0x45537553)
>diff -Nur 1 2 >3.patch
>vi 3.patch
1 --- 1 2006-09-08 15:57:29.000000000 +0800
2 +++ 2 2006-09-08 15:57:40.000000000 +0800
3 @@ -10,14 +10,14 @@
4 Version: 0x1
5 入口点地址: 0x8048350
6 程序头起点: 52 (bytes into file)
7 - Start of section headers: 2196 (bytes into file)
8 + Start of section headers: 3392 (bytes into file)
9 标志: 0x0
10 本头的大小: 52 (字节)
11 程序头大小: 32 (字节)
12 程序头数量: 8
13 节头大小: 40 (字节)
14 - 节头数量: 27
15 - 字符串表索引节头: 26
16 + 节头数量: 35
17 + 字符串表索引节头: 32
18
19 节头:
20 [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
21 @@ -47,7 +47,15 @@
22 [23] .data PROGBITS 0804969c 00069c 00000c 00 WA 0 0 4
23 [24] .bss NOBITS 080496a8 0006a8 000004 00 WA 0 0 4
24 [25] .comment PROGBITS 00000000 0006a8 000117 00 0 0 1
25 - [26] .shstrtab STRTAB 00000000 0007bf 0000d2 00 0 0 1
26 + [26] .debug_aranges PROGBITS 00000000 0007c0 000058 00 0 0 8
27 + [27] .debug_pubnames PROGBITS 00000000 000818 000025 00 0 0 1
28 + [28] .debug_info PROGBITS 00000000 00083d 000191 00 0 0 1
29 + [29] .debug_abbrev PROGBITS 00000000 0009ce 000062 00 0 0 1
30 + [30] .debug_line PROGBITS 00000000 000a30 000137 00 0 0 1
31 + [31] .debug_str PROGBITS 00000000 000b67 0000a5 01 MS 0 0 1
32 + [32] .shstrtab STRTAB 00000000 000c0c 000132 00 0 0 1
33 + [33] .symtab SYMTAB 00000000 0012b8 000570 10 34 65 4
34 + [34] .strtab STRTAB 00000000 001828 0002d9 00 0 0 1
35 Key to Flags:
36 W (write), A (alloc), X (execute), M (merge), S (strings)
37 I (info), L (link order), G (group), x (unknown)
38 @@ -124,6 +132,96 @@
39 5: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
40 6: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
41
42 +Symbol table '.symtab' contains 87 entries:
43 + Num: Value Size Type Bind Vis Ndx Name
44 + 0: 00000000 0 NOTYPE LOCAL DEFAULT UND
45 + 1: 08048134 0 SECTION LOCAL DEFAULT 1
46 + 2: 08048148 0 SECTION LOCAL DEFAULT 2
47 + 3: 08048168 0 SECTION LOCAL DEFAULT 3
48 + 4: 08048180 0 SECTION LOCAL DEFAULT 4
49 + 5: 080481b0 0 SECTION LOCAL DEFAULT 5
50 + 6: 08048220 0 SECTION LOCAL DEFAULT 6
51 + 7: 08048286 0 SECTION LOCAL DEFAULT 7
52 + 8: 08048294 0 SECTION LOCAL DEFAULT 8
53 + 9: 080482b4 0 SECTION LOCAL DEFAULT 9
54 + 10: 080482bc 0 SECTION LOCAL DEFAULT 10
55 + 11: 080482dc 0 SECTION LOCAL DEFAULT 11
56 + 12: 080482f4 0 SECTION LOCAL DEFAULT 12
57 + 13: 08048350 0 SECTION LOCAL DEFAULT 13
58 + 14: 0804856c 0 SECTION LOCAL DEFAULT 14
59 + 15: 08048588 0 SECTION LOCAL DEFAULT 15
60 + 16: 0804859c 0 SECTION LOCAL DEFAULT 16
61 + 17: 080495a0 0 SECTION LOCAL DEFAULT 17
62 + 18: 080495a8 0 SECTION LOCAL DEFAULT 18
63 + 19: 080495b0 0 SECTION LOCAL DEFAULT 19
64 + 20: 080495b4 0 SECTION LOCAL DEFAULT 20
65 + 21: 0804967c 0 SECTION LOCAL DEFAULT 21
66 + 22: 08049680 0 SECTION LOCAL DEFAULT 22
67 + 23: 0804969c 0 SECTION LOCAL DEFAULT 23
68 + 24: 080496a8 0 SECTION LOCAL DEFAULT 24
69 + 25: 00000000 0 SECTION LOCAL DEFAULT 25
70 + 26: 00000000 0 SECTION LOCAL DEFAULT 26
71 + 27: 00000000 0 SECTION LOCAL DEFAULT 27
72 + 28: 00000000 0 SECTION LOCAL DEFAULT 28
73 + 29: 00000000 0 SECTION LOCAL DEFAULT 29
74 + 30: 00000000 0 SECTION LOCAL DEFAULT 30
75 + 31: 00000000 0 SECTION LOCAL DEFAULT 31
76 + 32: 00000000 0 SECTION LOCAL DEFAULT 32
77 + 33: 00000000 0 SECTION LOCAL DEFAULT 33
78 + 34: 00000000 0 SECTION LOCAL DEFAULT 34
79 + 35: 00000000 0 FILE LOCAL DEFAULT ABS abi-note.S
80 + 36: 00000000 0 FILE LOCAL DEFAULT ABS suse-note.S
81 + 37: 00000000 0 FILE LOCAL DEFAULT ABS ../sysdeps/i386/elf/start
82 + 38: 00000000 0 FILE LOCAL DEFAULT ABS init.c
83 + 39: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c
84 + 40: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/packages/BUILD/g
85 + 41: 08048374 0 FUNC LOCAL DEFAULT 13 call_gmon_start
86 + 42: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
87 + 43: 080495a0 0 OBJECT LOCAL DEFAULT 17 __CTOR_LIST__
88 + 44: 080495a8 0 OBJECT LOCAL DEFAULT 18 __DTOR_LIST__
89 + 45: 080495b0 0 OBJECT LOCAL DEFAULT 19 __JCR_LIST__
90 + 46: 080496a8 1 OBJECT LOCAL DEFAULT 24 completed.5751
91 + 47: 080496a4 0 OBJECT LOCAL DEFAULT 23 p.5749
92 + 48: 080483a0 0 FUNC LOCAL DEFAULT 13 __do_global_dtors_aux
93 + 49: 080483d0 0 FUNC LOCAL DEFAULT 13 frame_dummy
94 + 50: 00000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
95 + 51: 080495a4 0 OBJECT LOCAL DEFAULT 17 __CTOR_END__
96 + 52: 080495ac 0 OBJECT LOCAL DEFAULT 18 __DTOR_END__
97 + 53: 0804859c 0 OBJECT LOCAL DEFAULT 16 __FRAME_END__
98 + 54: 080495b0 0 OBJECT LOCAL DEFAULT 19 __JCR_END__
99 + 55: 08048540 0 FUNC LOCAL DEFAULT 13 __do_global_ctors_aux
100 + 56: 00000000 0 FILE LOCAL DEFAULT ABS initfini.c
101 + 57: 00000000 0 FILE LOCAL DEFAULT ABS /usr/src/packages/BUILD/g
102 + 58: 00000000 0 FILE LOCAL DEFAULT ABS main.c
103 + 59: 00000000 0 FILE LOCAL DEFAULT ABS max.c
104 + 60: 00000000 0 FILE LOCAL DEFAULT ABS min.c
105 + 61: 080495b4 0 OBJECT LOCAL HIDDEN 20 _DYNAMIC
106 + 62: 080495a0 0 NOTYPE LOCAL HIDDEN ABS __init_array_end
107 + 63: 08049680 0 OBJECT LOCAL HIDDEN 22 _GLOBAL_OFFSET_TABLE_
108 + 64: 080495a0 0 NOTYPE LOCAL HIDDEN ABS __init_array_start
109 + 65: 08048588 4 OBJECT GLOBAL DEFAULT 15 _fp_hw
110 + 66: 080496a0 0 OBJECT GLOBAL HIDDEN 23 __dso_handle
111 + 67: 080484d0 5 FUNC GLOBAL DEFAULT 13 __libc_csu_fini
112 + 68: 080482dc 0 FUNC GLOBAL DEFAULT 11 _init
113 + 69: 00000000 65 FUNC GLOBAL DEFAULT UND scanf@@GLIBC_2.0
114 + 70: 08048350 0 FUNC GLOBAL DEFAULT 13 _start
115 + 71: 0804846c 43 FUNC GLOBAL DEFAULT 13 max
116 + 72: 080484e0 92 FUNC GLOBAL DEFAULT 13 __libc_csu_init
117 + 73: 080496a8 0 NOTYPE GLOBAL DEFAULT ABS __bss_start
118 + 74: 080483f4 120 FUNC GLOBAL DEFAULT 13 main
119 + 75: 00000000 415 FUNC GLOBAL DEFAULT UND __libc_start_main@@GLIBC_
120 + 76: 0804969c 0 NOTYPE WEAK DEFAULT 23 data_start
121 + 77: 08048498 43 FUNC GLOBAL DEFAULT 13 min
122 + 78: 00000000 57 FUNC GLOBAL DEFAULT UND printf@@GLIBC_2.0
123 + 79: 0804856c 0 FUNC GLOBAL DEFAULT 14 _fini
124 + 80: 080496a8 0 NOTYPE GLOBAL DEFAULT ABS _edata
125 + 81: 0804853c 0 FUNC GLOBAL HIDDEN 13 __i686.get_pc_thunk.bx
126 + 82: 080496ac 0 NOTYPE GLOBAL DEFAULT ABS _end
127 + 83: 0804858c 4 OBJECT GLOBAL DEFAULT 15 _IO_stdin_used
128 + 84: 0804969c 0 NOTYPE GLOBAL DEFAULT 23 __data_start
129 + 85: 00000000 0 NOTYPE WEAK DEFAULT UND _Jv_RegisterClasses
130 + 86: 00000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
131 +
132 Histogram for bucket list length (total of 3 buckets):
133 Length Number % of total Coverage
134 0 0 ( 0.0%)
可见,.symtab与.debug节已经没有了。对于库文件来说,没有.symtab会丢失很多信息,
很可能会导致链接的时候出问题,因此慎用strip。