size
Print the size of code, data, and BSS sections in an object file
By CMD Script Team · 4 min read · Last updated
size [OPTIONS] FILE...Options
| Flag | Description |
|---|---|
-A | Use the 'System V' output format, listing each section individually with its size |
-B | Use the 'Berkeley' output format (the default), showing totals for text, data, and bss |
-d | Print section sizes in decimal (the default for Berkeley format) |
-x | Print section sizes in hexadecimal |
-t | Print a total across all listed files at the end |
--format=FORMAT | Explicitly choose the output format, e.g. sysv or berkeley |
Distribution compatibility
- Ubuntu
- Debian
- Fedora
- Arch
- macOS (via Xcode Command Line Tools, part of llvm-size/binutils)
What it does
size is a GNU binutils tool that reports the size of the standard sections — text
(code), data (initialized variables), and bss (uninitialized variables) — inside a
compiled object file, library, or executable, along with a decimal and hexadecimal
grand total. It's primarily used to understand how much storage (flash/disk) and
runtime memory (RAM) a binary will require, which is especially important on
resource-constrained targets like embedded systems and microcontrollers.
Beginner examples
size myprogram— show text/data/bss totals in the default Berkeley formatsize *.o— show sizes for every object file matching the glob, one line per filesize -A myprogram— show a detailed per-section breakdown (System V format)size -x myprogram— show the totals in hexadecimal instead of decimal
size myprogram
Advanced examples
- Compare sizes across several binaries with a combined total:
size -t app1 app2 app3 - Inspect every named section (including
.rodata,.debug_info, etc.), not just the three summary categories:size -A -x firmware.elf - Track binary growth over time in a build script by capturing
sizeoutput after each build and diffing it against a previous run. - Check the size impact of enabling debug symbols by comparing
size appbefore and after building with-g.
size -A -d firmware.elf
Common mistakes
- Confusing
size's reported totals with the file's size on disk — the file also contains headers, symbol tables, and debug info thatsize's text/data/bss summary doesn't include (usels -lhordu -hfor actual file size). - Forgetting that
bssdoesn't occupy space in the file itself, only at runtime — a large uninitialized array bloats runtime RAM usage but not disk size. - Ignoring
sizeoutput entirely on embedded projects until a build unexpectedly overflows flash or RAM — it's more useful checked continuously during development. - Comparing
sizeoutput between a stripped and unstripped binary and expecting text/data/bss to differ — stripping removes symbol tables and debug info, not the actual code/data/bss sectionssizereports on.
Tips
- Use
-Awhen you need to see individual sections like.rodataor.debug_inforather than just the three summary buckets from the default Berkeley format. - On embedded targets, watch the
dectotal against your chip's flash and RAM limits after every significant change —sizeis a fast way to catch overflow before flashing hardware. - Combine
sizewith a CI step that fails the build if text+data exceeds a defined budget, to catch binary bloat regressions automatically.
Best practices
- Check
sizeoutput as part of the build for any project targeting constrained hardware (microcontrollers, bootloaders) rather than discovering overflow at flash time. - Use
-Afor detailed section-by-section review when optimizing for size, since the Berkeley summary can hide which specific section (e.g..rodatavs.text) is actually growing. - Track
sizeoutput over time (e.g. in CI logs) to catch gradual binary bloat before it becomes a problem.
Try it yourself
A simulated shell with a sample home directory — experiment freely, nothing leaves your browser. Type help to list supported commands.
Real-world use cases
- Verifying a firmware image still fits within a microcontroller's flash and RAM budget after adding a new feature.
- Comparing the memory footprint of two implementations of the same function to choose the leaner one for a size-constrained target.
- Diagnosing unexpectedly large RAM usage by checking whether it's coming from
bss(uninitialized globals) rather thandataortext. - Tracking binary size growth release-over-release as part of a size-budget CI check.
Common interview questions
- What do the text, data, and bss sections represent? text is compiled machine code, data is initialized global/static variables stored in the file, and bss is uninitialized global/static variables that occupy runtime memory but aren't stored in the file (the loader zero-fills them at load time).
- Why is size especially useful in embedded development? Because flash and RAM are both tightly limited on microcontrollers, and size gives a fast way to check whether a build fits its hardware budget before flashing.
- Does a smaller bss section reduce the file size on disk? No — bss doesn't take file space at all regardless of size, since it's zero-filled at load time; it only affects runtime RAM usage.
- How would you get a detailed, per-section view instead of the summary totals? Use size -A (System V format), which lists every named section individually instead of just the text/data/bss summary.
Frequently Asked Questions
What do text, data, and bss mean in size's output?
text is compiled machine code (read-only, executable). data is initialized global/static variables, stored in the binary and loaded into RAM. bss is uninitialized global/static variables, which take up runtime memory but aren't stored in the file itself (the loader zero-fills them).
Why would I care about the output of size?
It's the standard way to check how much flash and RAM a compiled binary will need, which matters enormously for embedded and microcontroller development where both are tightly limited. It's also useful for tracking binary bloat over time in any size-sensitive build.
Does size measure the file's size on disk?
Not exactly. size reports the size of specific sections (text, data, bss, and with -A, others like .rodata or .debug) as recorded in the object file's headers, which is more meaningful than the raw file size for understanding runtime memory footprint.
Cheat sheet
Download a quick-reference cheat sheet for size.