Home / Alt manpages / llvm-size-20(1)

  • llvm-size-20(1)
  • User command
  • linux

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.

  • Time: about ten minutes.
  • You need: a shell and an ELF object, executable or shared library to inspect.
  • What it will not touch: the command is read-only. It does not rewrite the input, strip symbols or change a binary. No elevated privileges are normally needed.

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.
  • Version string varies. The exact packaging suffix and build description can differ on another machine.
  • Checkpoint. The command should report LLVM 20 and run from the path you intend.
  • If it is missing, install the package through your normal system package process rather than copying an executable from an unrelated LLVM release.

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.

  • text is the program's code and read-only content as reported by this format.
  • data is initialised writable storage.
  • bss is zero-initialised storage.
  • dec and hex are totals in decimal and hexadecimal, useful indicators rather than a complete accounting: headers, symbol tables, debug information and alignment can also occupy bytes.

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
  • -d, -o and -x are the short aliases for decimal, octal and hexadecimal.
  • Hexadecimal mode prefixes the section values with 0x, while the existing total columns stay decimal and hexadecimal.
  • Do not parse by column position alone if a script allows multiple formats; label the chosen radix in your own report.

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.

  • --common prints common symbols from an ELF file, adding them to the BSS figure in Berkeley format. Use it only when you understand how your compiler and linker represent common storage, and document the choice: it does not discover every source-level global variable.
  • @FILE arguments let you read options from a file, per the installed manpage. Treat such a file as executable configuration: inspect it before use, especially in a build directory shared by other users, and never pass an untrusted options file to an automated size job.

Done means

  • Version confirmed. llvm-size-20 --version reports the expected LLVM 20 installation.
  • Columns understood. You can read the default text, data, BSS, decimal and hexadecimal columns.
  • Format recorded. Your report states the chosen radix and output format.
  • Sections located. You used SysV output when a section-level explanation was needed.
  • Totals kept honest. Any total compares a deliberate, stable list of inputs rather than pretending to be a full memory or file-size measurement.
  • Failures caught. A failed input is reported as an error, and no binary or build output was changed.