xref: /llvm-project/llvm/docs/CommandGuide/llvm-size.rst (revision bbce75e352be0637305a1b59ac5eca7175bceece)
1llvm-size - print size information
2==================================
3
4.. program:: llvm-size
5
6SYNOPSIS
7--------
8
9:program:`llvm-size` [*options*] [*input...*]
10
11DESCRIPTION
12-----------
13
14:program:`llvm-size` is a tool that prints size information for binary files.
15It is intended to be a drop-in replacement for GNU's :program:`size`.
16
17The tool prints size information for each ``input`` specified. If no input is
18specified, the program prints size information for ``a.out``. If "``-``" is
19specified as an input file, :program:`llvm-size` reads a file from the standard
20input stream. If an input is an archive, size information will be displayed for
21all its members.
22
23OPTIONS
24-------
25
26.. option:: -A
27
28 Equivalent to :option:`--format` with a value of ``sysv``.
29
30.. option:: --arch=<arch>
31
32 Architecture(s) from Mach-O universal binaries to display information for.
33
34.. option:: -B
35
36 Equivalent to :option:`--format` with a value of ``berkeley``.
37
38.. option:: --common
39
40 Include ELF common symbol sizes in bss size for ``berkeley`` output format, or
41 as a separate section entry for ``sysv`` output. If not specified, these
42 symbols are ignored.
43
44.. option:: -d
45
46 Equivalent to :option:`--radix` with a value of ``10``.
47
48.. option:: -l
49
50 Display verbose address and offset information for segments and sections in
51 Mach-O files in ``darwin`` format.
52
53.. option:: --format=<format>
54
55 Set the output format to the ``<format>`` specified. Available ``<format>``
56 options are ``berkeley`` (the default), ``sysv`` and ``darwin``.
57
58 Berkeley output summarises text, data and bss sizes in each file, as shown
59 below for a typical pair of ELF files:
60
61 .. code-block:: console
62
63  $ llvm-size --format=berkeley test.o test2.o
64     text    data     bss     dec     hex filename
65      182      16       5     203      cb test.elf
66       82       8       1      91      5b test2.o
67
68 For Mach-O files, the output format is slightly different:
69
70 .. code-block:: console
71
72  $ llvm-size --format=berkeley macho.obj macho2.obj
73  __TEXT  __DATA  __OBJC  others  dec     hex
74  4       8       0       0       12      c       macho.obj
75  16      32      0       0       48      30      macho2.obj
76
77 Sysv output displays size and address information for most sections, with each
78 file being listed separately:
79
80 .. code-block:: console
81
82  $ llvm-size --format=sysv test.elf test2.o
83     test.elf  :
84     section       size      addr
85     .eh_frame       92   2097496
86     .text           90   2101248
87     .data           16   2105344
88     .bss             5   2105360
89     .comment       209         0
90     Total          412
91
92     test2.o  :
93     section             size   addr
94     .text                 26      0
95     .data                  8      0
96     .bss                   1      0
97     .comment             106      0
98     .note.GNU-stack        0      0
99     .eh_frame             56      0
100     .llvm_addrsig          2      0
101     Total                199
102
103 ``darwin`` format only affects Mach-O input files. If an input of a different
104 file format is specified, :program:`llvm-size` falls back to ``berkeley``
105 format. When producing ``darwin`` format, the tool displays information about
106 segments and sections:
107
108 .. code-block:: console
109
110  $ llvm-size --format=darwin macho.obj macho2.obj
111     macho.obj:
112     Segment : 12
113             Section (__TEXT, __text): 4
114             Section (__DATA, __data): 8
115             total 12
116     total 12
117     macho2.obj:
118     Segment : 48
119             Section (__TEXT, __text): 16
120             Section (__DATA, __data): 32
121             total 48
122     total 48
123
124.. option:: --help, -h
125
126 Display a summary of command line options.
127
128.. option:: -m
129
130 Equivalent to :option:`--format` with a value of ``darwin``.
131
132.. option:: -o
133
134 Equivalent to :option:`--radix` with a value of ``8``.
135
136.. option:: --radix=<value>
137
138 Display size information in the specified radix. Permitted values are ``8``,
139 ``10`` (the default) and ``16`` for octal, decimal and hexadecimal output
140 respectively.
141
142 Example:
143
144 .. code-block:: console
145
146  $ llvm-size --radix=8 test.o
147     text    data     bss     oct     hex filename
148     0152      04      04     162      72 test.o
149
150  $ llvm-size --radix=10 test.o
151     text    data     bss     dec     hex filename
152      106       4       4     114      72 test.o
153
154  $ llvm-size --radix=16 test.o
155     text    data     bss     dec     hex filename
156     0x6a     0x4     0x4     114      72 test.o
157
158.. option:: --totals, -t
159
160 Applies only to ``berkeley`` output format. Display the totals for all listed
161 fields, in addition to the individual file listings.
162
163 Example:
164
165 .. code-block:: console
166
167  $ llvm-size --totals test.elf test2.o
168     text    data     bss     dec     hex filename
169      182      16       5     203      cb test.elf
170       82       8       1      91      5b test2.o
171      264      24       6     294     126 (TOTALS)
172
173.. option:: --version
174
175 Display the version of the :program:`llvm-size` executable.
176
177.. option:: -x
178
179 Equivalent to :option:`--radix` with a value of ``16``.
180
181.. option:: @<FILE>
182
183 Read command-line options from response file ``<FILE>``.
184
185EXIT STATUS
186-----------
187
188:program:`llvm-size` exits with a non-zero exit code if there is an error.
189Otherwise, it exits with code 0.
190
191BUGS
192----
193
194To report bugs, please visit <https://github.com/llvm/llvm-project/labels/tools:llvm-size/>.
195