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, --format=sysv
    Use System V output format (default on some systems).

-B, --format=berkeley
    Use Berkeley output format.

-C, --radix=number
    Use the specified radix (number) for the size output.

-d, --radix=10
    Display sizes in decimal (default).

-f, --format=macho
    Use Mach-O output format (for macOS).

-h, --help
    Display help message.

-i, --include-intermediates
    Include sizes of intermediate object files.

-l, --format=ldscript
    Display the total sizes of all loadable output sections.

-t, --format=traditional
    Use traditional output format.

-V, --version
    Display version information.

-x, --radix=16
    Display sizes in hexadecimal.

-z, --common
    Display total size of common symbols.

DESCRIPTION

The size command lists the section sizes – and the total size – for object files. It's a valuable tool for understanding the memory footprint of compiled programs and libraries. It parses the object file format (e.g., ELF) and extracts the sizes of sections like .text (code), .data (initialized data), and .bss (uninitialized data).

This information is useful for optimizing memory usage, debugging, and understanding how a program is laid out in memory. The output typically includes the size in bytes for each section, along with a decimal and hexadecimal representation of the total size. The size command can be used on executables, shared libraries, and object files.

Different architectures and operating systems may influence the layout and naming of sections, but the underlying principle of displaying section sizes remains the same. It's a quick way to get a high-level overview of the memory requirements of a program without needing to delve into detailed memory maps or debugging sessions.

OUTPUT FORMAT DETAILS

The default output format depends on the system. System V format displays the size of each section, followed by the total size. Berkeley format displays the total size first, followed by the sizes of .text, .data, and .bss. The format options influence how this information is presented.

SEE ALSO

nm(1), objdump(1), readelf(1)

Copied to clipboard