LinuxCommandLibrary

size

Display executable size sections

TLDR

Display the size of sections in a given object or executable file

$ size [path/to/file]
copy

Display the size of sections in a given object or executable file in [o]ctal
$ size [[-o|--radix=8]] [path/to/file]
copy

Display the size of sections in a given object or executable file in [d]ecimal
$ size [[-d|--radix=10]] [path/to/file]
copy

Display the size of sections in a given object or executable file in he[x]adecimal
$ size [[-x|--radix=16]] [path/to/file]
copy

SYNOPSIS

size [options] object-file...

PARAMETERS

-A or --format=SysV
    Uses the System V output format, which typically provides a more detailed breakdown of sections compared to the default Berkeley format.

-B or --format=Berkeley
    Uses the Berkeley output format, which is often the default and provides a concise output of text, data, bss, and total sizes.

-d or --radix=10
    Displays the section sizes in decimal (base 10) format. This is the default when using the Berkeley format.

-o or --radix=8
    Displays the section sizes in octal (base 8) format.

-x or --radix=16
    Displays the section sizes in hexadecimal (base 16) format.

--common
    Includes the size of common symbols in the output. Common symbols are uninitialized global variables that might be defined in multiple object files and resolved at link time.

-V or --version
    Displays the version number of the size command and exits.

-H or --help
    Displays a brief usage message and exits.

DESCRIPTION

The size command is a utility in Linux systems, typically part of the GNU Binutils package, used to display the sizes of various sections within object files, executables, or archive members. It primarily reports the sizes of the text (executable code), data (initialized variables), and bss (uninitialized variables) sections, along with their total sum. This command is invaluable for developers and programmers to quickly assess the memory footprint of their compiled programs, shared libraries, or object files. By providing insights into how much space each section occupies, it helps in optimizing code for size, especially in embedded systems or memory-constrained environments. The output can be displayed in decimal, octal, or hexadecimal formats, offering flexibility for different analytical needs. It is an essential tool for understanding the low-level structure and memory usage of compiled binaries.

CAVEATS

The size command works exclusively with executable and object files (e.g., ELF, COFF, a.out formats). It cannot be used to determine the size of regular text files, directories, or other non-binary file types.

The reported 'bss' size represents space reserved for uninitialized data that is zeroed out at runtime. While it contributes to the process's memory footprint, it does not occupy actual disk space within the executable file itself.

UNDERSTANDING SECTIONS

The output of size typically shows three main sections:

text: This section contains the executable instructions (code) of the program.

data: This section holds initialized global and static variables, meaning variables that have a predefined value at compile time.

bss: (Block Started by Symbol) This section contains uninitialized global and static variables. These variables are guaranteed to be initialized to zero by the system when the program starts, but they do not occupy space in the executable file itself (only their size is recorded) to save disk space. Memory for them is allocated at runtime.

The total size displayed is the sum of text, data, and bss sections, representing the approximate memory footprint when loaded.

HISTORY

The size command has a long history, being an integral part of Unix-like systems and their development toolchains. Its core functionality of reporting section sizes dates back to early Unix versions. In modern Linux, it is primarily provided by the GNU Binutils project, a collection of binary tools that includes assemblers, linkers, and tools for working with binary files. Its continuous development as part of Binutils ensures compatibility with various object file formats (like ELF) and architectures, making it a staple for software developers globally.

SEE ALSO

objdump(1), readelf(1), nm(1), ld(1), ar(1)

Copied to clipboard