1、size工具介绍
size工具会列出程序文件中各段的大小。我们可以查看帮忙:
$ size --help
Usage: size [option(s)] [file(s)]
Displays the sizes of sections inside binary files
If no input file(s) are specified, a.out is assumed
The options are:
-A|-B --format={sysv|berkeley} Select output style (default is berkeley)
-o|-d|-x --radix={8|10|16} Display numbers in octal, decimal or hex
-t --totals Display the total sizes (Berkeley only)
--common Display total size for *COM* syms
--target=<bfdname> Set the binary file format
@<file> Read options from <file>
-h --help Display this information
-v --version Display the program's versionsize: supported targets: elf64-x86-64 elf32-i386 elf32-iamcu elf32-x86-64 a.out-i386-linux pei-i386 pei-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big elf32-little elf32-big pe-x86-64 pe-bigobj-x86-64 pe-i386 plugin srec symbolsrec verilog tekhex binary ihex
Report bugs to <http://www.sourceware.org/bugzilla/>
2、例子
以我们之前的一个动态库,一个静态库,一个可执行程序为例子:
2.1 表示方法切换
$ size main
text data bss dec hex filename
1275 552 8 1835 72b main$ size main -B
text data bss dec hex filename
1275 552 8 1835 72b main
$ size main -A
main :
section size addr
.interp 28 4194872
.note.ABI-tag 32 4194900
.note.gnu.build-id 36 4194932
.gnu.hash 28 4194968
.dynsym 96 4195000
.dynstr 63 4195096
.gnu.version 8 4195160
.gnu.version_r 32 4195168
.rela.dyn 24 4195200
.rela.plt 48 4195224
.init 26 4195272
.plt 48 4195312
.plt.got 8 4195360
.text 434 4195376
.fini 9 4195812
.rodata 19 4195824
.eh_frame_hdr 60 4195844
.eh_frame 276 4195904
.init_array 8 6295056
.fini_array 8 6295064
.jcr 8 6295072
.dynamic 464 6295080
.got 8 6295544
.got.plt 40 6295552
.data 16 6295592
.bss 8 6295608
.comment 53 0
Total 1888
可见默认就是-B显示,即berkeley。-A是sysv,具体什么意思也不懂啦,但是从结果看就是各个段分别显示。
2.2 十进制、八进制、十六进制显示
$ size main -o
text data bss oct hex filename
02373 01050 010 3453 72b main
$ size main -d
text data bss dec hex filename
1275 552 8 1835 72b main
$ size main -x
text data bss dec hex filename
0x4fb 0x228 0x8 1835 72b main