blob: ccdcf13eb597fcba5d9ab5b995c4259c85c5852a [file] [log] [blame]
James Hendersone26ca962019-07-03 14:21:48 +00001llvm-objcopy - object copying and editing tool
2==============================================
3
4.. program:: llvm-objcopy
5
6SYNOPSIS
7--------
8
9:program:`llvm-objcopy` [*options*] *input* [*output*]
10
11DESCRIPTION
12-----------
13
14:program:`llvm-objcopy` is a tool to copy and manipulate objects. In basic
15usage, it makes a semantic copy of the input to the output. If any options are
16specified, the output may be modified along the way, e.g. by removing sections.
17
18If no output file is specified, the input file is modified in-place. If "-" is
19specified for the input file, the input is read from the program's standard
20input stream. If "-" is specified for the output file, the output is written to
21the standard output stream of the program.
22
23If the input is an archive, any requested operations will be applied to each
24archive member individually.
25
26The tool is still in active development, but in most scenarios it works as a
27drop-in replacement for GNU's :program:`objcopy`.
28
29GENERIC AND CROSS-PLATFORM OPTIONS
30----------------------------------
31
32The following options are either agnostic of the file format, or apply to
33multiple file formats.
34
35.. option:: --add-gnu-debuglink <debug-file>
36
37 Add a .gnu_debuglink section for ``<debug-file>`` to the output.
38
Sergey Dmitrievcdeaac52019-07-26 17:06:41 +000039.. option:: --add-section <section=file>
40
41 Add a section named ``<section>`` with the contents of ``<file>`` to the
42 output. For ELF objects the section will be of type `SHT_NOTE`, if the name
43 starts with ".note". Otherwise, it will have type `SHT_PROGBITS`. Can be
44 specified multiple times to add multiple sections.
45
Fangrui Song2f519d72019-09-14 01:36:31 +000046.. option:: --binary-architecture <arch>, -B
47
48 Ignored for compatibility.
49
James Hendersone26ca962019-07-03 14:21:48 +000050.. option:: --disable-deterministic-archives, -U
51
52 Use real values for UIDs, GIDs and timestamps when updating archive member
53 headers.
54
55.. option:: --discard-all, -x
56
57 Remove most local symbols from the output. Different file formats may limit
58 this to a subset of the local symbols. For example, file and section symbols in
59 ELF objects will not be discarded.
60
61.. option:: --enable-deterministic-archives, -D
62
63 Enable deterministic mode when copying archives, i.e. use 0 for archive member
64 header UIDs, GIDs and timestamp fields. On by default.
65
66.. option:: --help, -h
67
68 Print a summary of command line options.
69
70.. option:: --only-section <section>, -j
71
72 Remove all sections from the output, except for sections named ``<section>``.
73 Can be specified multiple times to keep multiple sections.
74
75.. option:: --regex
76
77 If specified, symbol and section names specified by other switches are treated
78 as extended POSIX regular expression patterns.
79
80.. option:: --remove-section <section>, -R
81
82 Remove the specified section from the output. Can be specified multiple times
83 to remove multiple sections simultaneously.
84
Fangrui Song671fb342019-10-02 12:41:25 +000085.. option:: --set-section-alignment <section>=<align>
86
87 Set the alignment of section ``<section>`` to `<align>``. Can be specified
88 multiple times to update multiple sections.
89
James Hendersone26ca962019-07-03 14:21:48 +000090.. option:: --strip-all-gnu
91
92 Remove all symbols, debug sections and relocations from the output. This option
93 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
94
95.. option:: --strip-all, -S
96
97 For ELF objects, remove from the output all symbols and non-alloc sections not
98 within segments, except for .gnu.warning sections and the section name table.
99
100 For COFF objects, remove all symbols, debug sections, and relocations from the
101 output.
102
103.. option:: --strip-debug, -g
104
105 Remove all debug sections from the output.
106
107.. option:: --strip-symbol <symbol>, -N
108
109 Remove all symbols named ``<symbol>`` from the output. Can be specified
110 multiple times to remove multiple symbols.
111
112.. option:: --strip-symbols <filename>
113
114 Remove all symbols whose names appear in the file ``<filename>``, from the
115 output. In the file, each line represents a single symbol name, with leading
116 and trailing whitespace ignored, as is anything following a '#'. Can be
117 specified multiple times to read names from multiple files.
118
119.. option:: --strip-unneeded-symbol <symbol>
120
121 Remove from the output all symbols named ``<symbol>`` that are local or
122 undefined and are not required by any relocation.
123
124.. option:: --strip-unneeded-symbols <filename>
125
126 Remove all symbols whose names appear in the file ``<filename>``, from the
127 output, if they are local or undefined and are not required by any relocation.
128 In the file, each line represents a single symbol name, with leading and
129 trailing whitespace ignored, as is anything following a '#'. Can be specified
130 multiple times to read names from multiple files.
131
132.. option:: --strip-unneeded
133
134 Remove from the output all local or undefined symbols that are not required by
James Henderson818e5c92019-09-13 13:26:52 +0000135 relocations. Also remove all debug sections.
James Hendersone26ca962019-07-03 14:21:48 +0000136
137.. option:: --version, -V
138
James Henderson778a5e52019-09-17 11:43:42 +0000139 Display the version of the :program:`llvm-objcopy` executable.
James Hendersone26ca962019-07-03 14:21:48 +0000140
Michael Pozulpc45fd0c2019-09-14 01:14:43 +0000141.. option:: @<FILE>
142
James Henderson778a5e52019-09-17 11:43:42 +0000143 Read command-line options and commands from response file `<FILE>`.
Michael Pozulpc45fd0c2019-09-14 01:14:43 +0000144
James Hendersone26ca962019-07-03 14:21:48 +0000145COFF-SPECIFIC OPTIONS
146---------------------
147
148The following options are implemented only for COFF objects. If used with other
149objects, :program:`llvm-objcopy` will either emit an error or silently ignore
150them.
151
152.. option:: --only-keep-debug
153
154 Remove the contents of non-debug sections from the output, but keep the section
155 headers.
156
157ELF-SPECIFIC OPTIONS
158--------------------
159
160The following options are implemented only for ELF objects. If used with other
161objects, :program:`llvm-objcopy` will either emit an error or silently ignore
162them.
163
James Hendersone26ca962019-07-03 14:21:48 +0000164.. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
165
James Henderson1a517a42019-07-05 11:57:07 +0000166 Add a new symbol called ``<name>`` to the output symbol table, in the section
167 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
168 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
169 properties. Accepted values are:
James Hendersone26ca962019-07-03 14:21:48 +0000170
171 - `global` = the symbol will have global binding.
172 - `local` = the symbol will have local binding.
173 - `weak` = the symbol will have weak binding.
174 - `default` = the symbol will have default visibility.
175 - `hidden` = the symbol will have hidden visibility.
Chris Jacksone5cdfbc2019-08-15 09:45:09 +0000176 - `protected` = the symbol will have protected visibility.
James Hendersone26ca962019-07-03 14:21:48 +0000177 - `file` = the symbol will be an `STT_FILE` symbol.
178 - `section` = the symbol will be an `STT_SECTION` symbol.
179 - `object` = the symbol will be an `STT_OBJECT` symbol.
180 - `function` = the symbol will be an `STT_FUNC` symbol.
181 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
182
183 Additionally, the following flags are accepted but ignored: `debug`,
184 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
185
186 Can be specified multiple times to add multiple symbols.
187
188.. option:: --allow-broken-links
189
James Henderson1b103862019-09-24 13:41:39 +0000190 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
191 section references. Any invalid sh_link fields will be set to zero.
James Hendersone26ca962019-07-03 14:21:48 +0000192
James Hendersone26ca962019-07-03 14:21:48 +0000193.. option:: --build-id-link-dir <dir>
194
195 Set the directory used by :option:`--build-id-link-input` and
196 :option:`--build-id-link-output`.
197
198.. option:: --build-id-link-input <suffix>
199
200 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
201 specified by :option:`--build-id-link-dir`. The path used is derived from the
202 hex build ID.
203
204.. option:: --build-id-link-output <suffix>
205
206 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
207 specified by :option:`--build-id-link-dir`. The path used is derived from the
208 hex build ID.
209
210.. option:: --change-start <incr>, --adjust-start
211
212 Add ``<incr>`` to the program's start address. Can be specified multiple
213 times, in which case the values will be applied cumulatively.
214
215.. option:: --compress-debug-sections [<style>]
216
217 Compress DWARF debug sections in the output, using the specified style.
218 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
219 specified.
220
221.. option:: --decompress-debug-sections
222
223 Decompress any compressed DWARF debug sections in the output.
224
225.. option:: --discard-locals, -X
226
227 Remove local symbols starting with ".L" from the output.
228
229.. option:: --dump-section <section>=<file>
230
231 Dump the contents of section ``<section>`` into the file ``<file>``. Can be
232 specified multiple times to dump multiple sections to different files.
233 ``<file>`` is unrelated to the input and output files provided to
234 :program:`llvm-objcopy` and as such the normal copying and editing
235 operations will still be performed. No operations are performed on the sections
236 prior to dumping them.
237
238.. option:: --extract-dwo
239
240 Remove all sections that are not DWARF .dwo sections from the output.
241
242.. option:: --extract-main-partition
243
244 Extract the main partition from the output.
245
246.. option:: --extract-partition <name>
247
248 Extract the named partition from the output.
249
250.. option:: --globalize-symbol <symbol>
251
252 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
253 Can be specified multiple times to mark multiple symbols.
254
255.. option:: --globalize-symbols <filename>
256
257 Read a list of names from the file ``<filename>`` and mark defined symbols with
258 those names as global in the output. In the file, each line represents a single
259 symbol, with leading and trailing whitespace ignored, as is anything following
260 a '#'. Can be specified multiple times to read names from multiple files.
261
262.. option:: --input-target <format>, -I
263
264 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
265 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
266 to determine the format automatically.
267
268.. option:: --keep-file-symbols
269
270 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
271
272.. option:: --keep-global-symbol <symbol>
273
274 Make all symbols local in the output, except for symbols with the name
275 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
276
277.. option:: --keep-global-symbols <filename>
278
279 Make all symbols local in the output, except for symbols named in the file
280 ``<filename>``. In the file, each line represents a single symbol, with leading
281 and trailing whitespace ignored, as is anything following a '#'. Can be
282 specified multiple times to read names from multiple files.
283
284.. option:: --keep-section <section>
285
286 When removing sections from the output, do not remove sections named
287 ``<section>``. Can be specified multiple times to keep multiple sections.
288
289.. option:: --keep-symbol <symbol>, -K
290
291 When removing symbols from the output, do not remove symbols named
292 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
293
294.. option:: --keep-symbols <filename>
295
296 When removing symbols from the output do not remove symbols named in the file
297 ``<filename>``. In the file, each line represents a single symbol, with leading
298 and trailing whitespace ignored, as is anything following a '#'. Can be
299 specified multiple times to read names from multiple files.
300
301.. option:: --localize-hidden
302
303 Make all symbols with hidden or internal visibility local in the output.
304
305.. option:: --localize-symbol <symbol>, -L
306
307 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
308 output. Can be specified multiple times to mark multiple symbols as local.
309
310.. option:: --localize-symbols <filename>
311
312 Read a list of names from the file ``<filename>`` and mark defined non-common
313 symbols with those names as local in the output. In the file, each line
314 represents a single symbol, with leading and trailing whitespace ignored, as is
315 anything following a '#'. Can be specified multiple times to read names from
316 multiple files.
Chris Jacksonfa1fe932019-08-30 10:17:16 +0000317
318.. option:: --new-symbol-visibility <visibility>
319
320 Specify the visibility of the symbols automatically created when using binary
321 input or :option:`--add-symbol`. Valid options are:
322
323 - `default`
324 - `hidden`
325 - `internal`
326 - `protected`
327
328 The default is `default`.
James Hendersone26ca962019-07-03 14:21:48 +0000329
330.. option:: --output-target <format>, -O
331
332 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
333 of valid ``<format>`` values. If unspecified, the output format is assumed to
334 be the same as the input file's format.
335
336.. option:: --prefix-alloc-sections <prefix>
337
338 Add ``<prefix>`` to the front of the names of all allocatable sections in the
339 output.
340
341.. option:: --prefix-symbols <prefix>
342
343 Add ``<prefix>`` to the front of every symbol name in the output.
344
345.. option:: --preserve-dates, -p
346
347 Preserve access and modification timestamps in the output.
348
349.. option:: --redefine-sym <old>=<new>
350
351 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
352 multiple times to rename multiple symbols.
353
354.. option:: --redefine-syms <filename>
355
356 Rename symbols in the output as described in the file ``<filename>``. In the
357 file, each line represents a single symbol to rename, with the old name and new
358 name separated by an equals sign. Leading and trailing whitespace is ignored,
359 as is anything following a '#'. Can be specified multiple times to read names
360 from multiple files.
361
362.. option:: --rename-section <old>=<new>[,<flag>,...]
363
364 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
365 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
366 supported flags. Can be specified multiple times to rename multiple sections.
367
368.. option:: --set-section-flags <section>=<flag>[,<flag>,...]
369
370 Set section properties in the output of section ``<section>`` based on the
371 specified ``<flag>`` values. Can be specified multiple times to update multiple
372 sections.
373
374 Following is a list of supported flags and their effects:
375
376 - `alloc` = add the `SHF_ALLOC` flag.
377 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
378 section.
379 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
380 - `code` = add the `SHF_EXECINSTR` flag.
381 - `merge` = add the `SHF_MERGE` flag.
382 - `strings` = add the `SHF_STRINGS` flag.
383 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
384 section.
385
386 The following flags are also accepted, but are ignored for GNU compatibility:
387 `noload`, `debug`, `data`, `rom`, `share`.
388
389.. option:: --set-start-addr <addr>
390
391 Set the start address of the output to ``<addr>``. Overrides any previously
392 specified :option:`--change-start` or :option:`--adjust-start` options.
393
394.. option:: --split-dwo <dwo-file>
395
396 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
397 ``<dwo-file>`` as the output file and no other options, and then with
398 :option:`--strip-dwo` on the input file.
399
400.. option:: --strip-dwo
401
402 Remove all DWARF .dwo sections from the output.
403
404.. option:: --strip-non-alloc
405
406 Remove from the output all non-allocatable sections that are not within
407 segments.
408
409.. option:: --strip-sections
410
411 Remove from the output all section headers and all section data not within
412 segments. Note that many tools will not be able to use an object without
413 section headers.
414
415.. option:: --target <format>, -F
416
417 Equivalent to :option:`--input-target` and :option:`--output-target` for the
418 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
419 values.
420
421.. option:: --weaken-symbol <symbol>, -W
422
423 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
424 be specified multiple times to mark multiple symbols as weak.
425
426.. option:: --weaken-symbols <filename>
427
428 Read a list of names from the file ``<filename>`` and mark global symbols with
429 those names as weak in the output. In the file, each line represents a single
430 symbol, with leading and trailing whitespace ignored, as is anything following
431 a '#'. Can be specified multiple times to read names from multiple files.
432
433.. option:: --weaken
434
435 Mark all defined global symbols as weak in the output.
436
437SUPPORTED FORMATS
438-----------------
439
440The following values are currently supported by :program:`llvm-objcopy` for the
441:option:`--input-target`, :option:`--output-target`, and :option:`--target`
442options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
443
444- `binary`
445- `ihex`
446- `elf32-i386`
447- `elf32-x86-64`
448- `elf64-x86-64`
449- `elf32-iamcu`
450- `elf32-littlearm`
451- `elf64-aarch64`
452- `elf64-littleaarch64`
453- `elf32-littleriscv`
454- `elf64-littleriscv`
455- `elf32-powerpc`
456- `elf32-powerpcle`
457- `elf64-powerpc`
458- `elf64-powerpcle`
459- `elf32-bigmips`
460- `elf32-ntradbigmips`
461- `elf32-ntradlittlemips`
462- `elf32-tradbigmips`
463- `elf32-tradlittlemips`
464- `elf64-tradbigmips`
465- `elf64-tradlittlemips`
466- `elf32-sparc`
467- `elf32-sparcel`
468
James Henderson8cf99a112019-07-08 11:41:54 +0000469Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
470suffix.
471
472BINARY INPUT AND OUTPUT
473-----------------------
474
475If `binary` is used as the value for :option:`--input-target`, the input file
476will be embedded as a data section in an ELF relocatable object, with symbols
477``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
478``_binary_<file_name>_size`` representing the start, end and size of the data,
479where ``<file_name>`` is the path of the input file as specified on the command
480line with non-alphanumeric characters converted to ``_``.
481
482If `binary` is used as the value for :option:`--output-target`, the output file
483will be a raw binary file, containing the memory image of the input file.
484Symbols and relocation information will be discarded. The image will start at
485the address of the first loadable section in the output.
James Hendersone26ca962019-07-03 14:21:48 +0000486
487EXIT STATUS
488-----------
489
490:program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
491Otherwise, it exits with code 0.
492
493BUGS
494----
495
496To report bugs, please visit <http://llvm.org/bugs/>.
497
498There is a known issue with :option:`--input-target` and :option:`--target`
499causing only ``binary`` and ``ihex`` formats to have any effect. Other values
500will be ignored and :program:`llvm-objcopy` will attempt to guess the input
501format.
502
503SEE ALSO
504--------
505
506:manpage:`llvm-strip(1)`