文章目录
上篇文章:【ARM 嵌入式 编译系列 10 – GCC 编译缩减可执行文件 elf 文件大小】
上篇文章:【ARM 嵌入式 编译系列 10.2 – 符号表与可执行程序分离详细讲解】
接着上篇文章 ARM 嵌入式 编译系列 10 – GCC 编译缩减可执行文件 elf 文件大小 的介绍,我们看下如何进一步缩小可执行文件test
的大小。上篇文章通过 strip --strip-debug test
已经将 可执行文件 test 的大小从 17464
减小到了15912
bytes 。
加下继续缩减就是删除 符号表了,使用:strip
命令,或者strip --strip-all
命令:
$ strip --strip-all test
ls -rtl test
-rwxrwxr-x 1 sam sam 14472 8月 14 12:34 test
此时的可执行程序test已经从15912 bytes
进一步减小到了14472bytes
了。
此时符号表已经不在了:
sam@sam-Think:~$ nm test
nm: test: no symbols
symtab
和strtab
2 个 section不见了,section 从31
个减少到了29
个:
sam@sam-Think:~$ readelf -S test
There are 29 section headers, starting at offset 0x3148:
Section Headers:
[Nr] Name Type Address Offset
Size EntSize Flags Link Info Align
[ 0] NULL 0000000000000000 00000000
0000000000000000 0000000000000000 0 0 0
[ 1] .interp PROGBITS 0000000000000318 00000318
000000000000001c 0000000000000000 A 0 0 1
[ 2] .note.gnu.pr[...] NOTE 0000000000000338 00000338
0000000000000030 0000000000000000 A 0 0 8
[ 3] .note.gnu.bu[...] NOTE 0000000000000368 00000368
0000000000000024 0000000000000000 A 0 0 4
[ 4] .note.ABI-tag NOTE 000000000000038c 0000038c
0000000000000020 0000000000000000 A 0 0 4
[ 5] .gnu.hash GNU_HASH 00000000000003b0 000003b0
0000000000000024 0000000000000000 A 6 0 8
[ 6] .dynsym DYNSYM 00000000000003d8 000003d8
00000000000000c0 0000000000000018 A 7 1 8