Measure ELF Section Sizes with llvm-size-20

llvm-size-20 reports the text, data and BSS contribution of an object file in one line, so you can watch a binary grow without guessing. You will learn to read the default summary, switch radix, break a total down by section and total several files together. The examples use LLVM 20.1.8, installed here from the llvm-20 package.

1. Check the installed command

Confirm that the versioned executable is the one found in your path:

$ command -v llvm-size-20
/usr/bin/llvm-size-20
$ llvm-size-20 --version
llvm-size-20
Ubuntu LLVM version 20.1.8
  Optimized build.

2. Read the default Berkeley-style summary

Start with a known executable. /bin/ls is only an example; substitute your own path when comparing a build:

$ llvm-size-20 /bin/ls
   text   data    bss    dec    hex filename
 128185   4936   4760 137881  21a99 /bin/ls

The default output has one row per input.

Checkpoint: run the command against a file you built and save the result alongside the build metadata. Compare like with like, using the same compiler options and the same llvm-size format; a larger on-disk file does not automatically mean a larger value in the three section columns.

3. Choose a radix deliberately

Use the long option when output is going into a report or script, so the unit is visible in the command itself:

$ llvm-size-20 --radix=10 /bin/ls
   text   data    bss    dec    hex filename
 128185   4936   4760 137881  21a99 /bin/ls
$ llvm-size-20 --radix=8 /bin/ls
   text   data    bss    oct    hex filename
0372271 011510 011230 415231  21a99 /bin/ls
$ llvm-size-20 --radix=16 /bin/ls
   text   data    bss    dec    hex filename
0x1f4b9  0x1348  0x1298 137881  21a99 /bin/ls

4. Inspect individual sections with SysV output

Berkeley output is compact. For a section-by-section view, request the System V format:

$ llvm-size-20 --format=sysv /bin/ls
/bin/ls  :
section                 size     addr
.interp                   28      792
.note.gnu.property        48      824
.note.gnu.build-id        36      872

The command continues with the remaining sections, so this sample shows only the start. This view earns its keep when a total changes and you need to find which named section moved: it reports section size and address, not a full ELF inspection. Reach for readelf when you need headers, flags, symbols or relocation details.

--format=berkeley selects the compact layout explicitly. --format=darwin is also accepted by the installed LLVM 20 command, useful when matching Darwin-style size reports, although an ELF input still produces the familiar size columns.

5. Compare several files and request totals

Pass multiple input paths after the options. With Berkeley format, --totals adds a final aggregate row:

$ llvm-size-20 --totals /bin/ls /usr/bin/true
   text      data       bss       dec       hex filename
 128185      4936      4760    137881     21a99 /bin/ls
  18383       900        16     19299      4b63 /usr/bin/true
 146568      5836      4776    157180     265fc (TOTALS)

The short alias is -t. Totals just add the reported section values, so do not treat them as a deduplicated memory footprint when object files share pages or a linker will discard sections.

When measuring a single linked executable, totals add no new information. When comparing several independent files, they can answer a narrow question, such as whether the selected set's reported text grew. Keep the input list stable between runs, and record whether you used --format=berkeley or another format.

Common traps

A missing path, a text file or an object from an unsupported format produces an error instead of a size row:

$ llvm-size-20 does-not-exist
llvm-size-20: error: 'does-not-exist': No such file or directory

Warning: treat a non-zero exit status as a failed measurement. Do not silence the diagnostic and record an empty result as zero; the wording may vary by build, so check the path first and rerun with the intended input.

Done means