This tutorial explains Linux “size” command, options and its usage with examples.
Description :
The GNU size utility lists the section sizes—and the total size—for each of the object or archive files objfile in its argument list. By default, one line of output is generated for each object file or each module in an archive.
objfile… are the object files to be examined. If none are specified, the file “a.out” will be used.
Usage :
size [-A|-B|–format=compatibility] {–help] [-d|-o|-x|–radix=number] [-t|–totals] [–target=bfdname] [-V|–version] [objfile…]
Options :
-A, -B, –format=compatibility
Using one of these options, you can choose whether the output from GNU size resembles output from System V size (using -A, or –format=sysv), or Berkeley size (using -B, or –format=berkeley). The default is the one-line format similar to Berkeley’s.
Here is an example of the Berkeley (default) format of output from size:
$ size --format=Berkeley ranlib size text data bss dec hex filename 294880 81920 11592 388392 5ed28 ranlib 294880 81920 11888 388688 5ee50 size
This is the same data, but displayed closer to System V conventions:
$ size --format=SysV ranlib size ranlib : section size addr .text 294880 8192 .data 81920 303104 .bss 11592 385024 Total 388392 size : section size addr .text 294880 8192 .data 81920 303104 .bss 11888 385024 Total 388688
–help
Show a summary of acceptable arguments and options.
-d, -o, -x, –radix=number
Using one of these options, you can control whether the size of each section is given in decimal (-d, or –radix=10); octal (-o, or –radix=8); or hexadecimal (-x, or –radix=16). In –radix=number, only the three values (8, 10, 16) are supported. The total size is always given in two radices; decimal and hexadecimal for -d or -x output, or octal and hexadecimal if you’re using -o.
-t, –totals
Show totals of all objects listed (Berkeley format listing mode only).
–target=bfdname
Specify that the object-code format for objfile is bfdname. This option may not be necessary; size can automatically recognize many formats.
-V, –version
Display the version number of size.
Examples :
Let us create a test.c file and compile it to create object file and executable.
$ cat >> test.c # include <stdio.h> main() { char a[]="strings program"; printf("Welcome to tutorial\n"); system("ls"); printf("%s",a); } ^C $ gcc test.c -o test.o
1. A Basic Example
$ size test.o text data bss dec hex filename 1581 584 8 2173 87d test.o
2. Display in octal
$ size -o a.out text data bss oct hex filename 03055 01110 010 4175 87d a.out
3. Dislay in Hexadecimal
$ size -x a.out text data bss dec hex filename 0x62d 0x248 0x8 2173 87d a.out
4. Display in System V format and hexadecimal values
$ size -Ax test.o test.o : section size addr .interp 0x1c 0x400238 .note.ABI-tag 0x20 0x400254 .note.gnu.build-id 0x24 0x400274 .gnu.hash 0x1c 0x400298 .dynsym 0xa8 0x4002b8 .dynstr 0x66 0x400360 .gnu.version 0xe 0x4003c6 .gnu.version_r 0x30 0x4003d8 .rela.dyn 0x18 0x400408 .rela.plt 0x90 0x400420 .init 0x1a 0x4004b0 .plt 0x70 0x4004d0 .text 0x204 0x400540 .fini 0x9 0x400744 .rodata 0x1e 0x400750 .eh_frame_hdr 0x34 0x400770 .eh_frame 0xd4 0x4007a8 .init_array 0x8 0x600e10 .fini_array 0x8 0x600e18 .jcr 0x8 0x600e20 .dynamic 0x1d0 0x600e28 .got 0x8 0x600ff8 .got.plt 0x48 0x601000 .data 0x10 0x601048 .bss 0x8 0x601058 .comment 0x2a 0x0 Total 0x8a7
5. Show total values of different files
$ cp test.c test1.c $ gcc test1.c -o test1.o $ size -t *.o text data bss dec hex filename 1581 584 8 2173 87d test1.o 1581 584 8 2173 87d test.o 3162 1168 16 4346 10fa (TOTALS) $ size -At *.o test1.o : section size addr .interp 28 4194872 .note.ABI-tag 32 4194900 .note.gnu.build-id 36 4194932 .gnu.hash 28 4194968 .dynsym 168 4195000 .dynstr 102 4195168 .gnu.version 14 4195270 .gnu.version_r 48 4195288 .rela.dyn 24 4195336 .rela.plt 144 4195360 .init 26 4195504 .plt 112 4195536 .text 516 4195648 .fini 9 4196164 .rodata 30 4196176 .eh_frame_hdr 52 4196208 .eh_frame 212 4196264 .init_array 8 6295056 .fini_array 8 6295064 .jcr 8 6295072 .dynamic 464 6295080 .got 8 6295544 .got.plt 72 6295552 .data 16 6295624 .bss 8 6295640 .comment 42 0 Total 2215 test.o : section size addr .interp 28 4194872 .note.ABI-tag 32 4194900 .note.gnu.build-id 36 4194932 .gnu.hash 28 4194968 .dynsym 168 4195000 .dynstr 102 4195168 .gnu.version 14 4195270 .gnu.version_r 48 4195288 .rela.dyn 24 4195336 .rela.plt 144 4195360 .init 26 4195504 .plt 112 4195536 .text 516 4195648 .fini 9 4196164 .rodata 30 4196176 .eh_frame_hdr 52 4196208 .eh_frame 212 4196264 .init_array 8 6295056 .fini_array 8 6295064 .jcr 8 6295072 .dynamic 464 6295080 .got 8 6295544 .got.plt 72 6295552 .data 16 6295624 .bss 8 6295640 .comment 42 0 Total 2215
Sanfoundry Global Education & Learning Series – 1000 Linux Tutorials.
- Buy Linux Books
- Apply for Linux Internship
- Practice Programming MCQs
- Apply for Programming Internship
- Buy Information Technology Books