GCC详解-Binutils工具之size

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 version

size: 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
 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值