1llvm-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
39.. 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
46.. option:: --binary-architecture <arch>, -B
47
48 Ignored for compatibility.
49
50.. 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-keep-debug
71
72 Produce a debug file as the output that only preserves contents of sections
73 useful for debugging purposes.
74
75 For ELF objects, this removes the contents of `SHF_ALLOC` sections that are not
76 `SHT_NOTE` by making them `SHT_NOBITS` and shrinking the program headers where
77 possible.
78
79.. option:: --only-section <section>, -j
80
81 Remove all sections from the output, except for sections named ``<section>``.
82 Can be specified multiple times to keep multiple sections.
83
84 For MachO objects, ``<section>`` must be formatted as
85 ``<segment name>,<section name>``.
86
87.. option:: --redefine-sym <old>=<new>
88
89 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
90 multiple times to rename multiple symbols.
91
92.. option:: --redefine-syms <filename>
93
94 Rename symbols in the output as described in the file ``<filename>``. In the
95 file, each line represents a single symbol to rename, with the old name and new
96 name separated by whitespace. Leading and trailing whitespace is ignored, as is
97 anything following a '#'. Can be specified multiple times to read names from
98 multiple files.
99
100.. option:: --regex
101
102 If specified, symbol and section names specified by other switches are treated
103 as extended POSIX regular expression patterns.
104
105.. option:: --remove-section <section>, -R
106
107 Remove the specified section from the output. Can be specified multiple times
108 to remove multiple sections simultaneously.
109
110.. option:: --set-section-alignment <section>=<align>
111
112 Set the alignment of section ``<section>`` to `<align>``. Can be specified
113 multiple times to update multiple sections.
114
115.. option:: --strip-all-gnu
116
117 Remove all symbols, debug sections and relocations from the output. This option
118 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
119
120.. option:: --strip-all, -S
121
122 For ELF objects, remove from the output all symbols and non-alloc sections not
123 within segments, except for .gnu.warning, .ARM.attribute sections and the
124 section name table.
125
126 For COFF and Mach-O objects, remove all symbols, debug sections, and
127 relocations from the output.
128
129.. option:: --strip-debug, -g
130
131 Remove all debug sections from the output.
132
133.. option:: --strip-symbol <symbol>, -N
134
135 Remove all symbols named ``<symbol>`` from the output. Can be specified
136 multiple times to remove multiple symbols.
137
138.. option:: --strip-symbols <filename>
139
140 Remove all symbols whose names appear in the file ``<filename>``, from the
141 output. In the file, each line represents a single symbol name, with leading
142 and trailing whitespace ignored, as is anything following a '#'. Can be
143 specified multiple times to read names from multiple files.
144
145.. option:: --strip-unneeded-symbol <symbol>
146
147 Remove from the output all symbols named ``<symbol>`` that are local or
148 undefined and are not required by any relocation.
149
150.. option:: --strip-unneeded-symbols <filename>
151
152 Remove all symbols whose names appear in the file ``<filename>``, from the
153 output, if they are local or undefined and are not required by any relocation.
154 In the file, each line represents a single symbol name, with leading and
155 trailing whitespace ignored, as is anything following a '#'. Can be specified
156 multiple times to read names from multiple files.
157
158.. option:: --strip-unneeded
159
160 Remove from the output all local or undefined symbols that are not required by
161 relocations. Also remove all debug sections.
162
163.. option:: --version, -V
164
165 Display the version of the :program:`llvm-objcopy` executable.
166
167.. option:: @<FILE>
168
169 Read command-line options and commands from response file `<FILE>`.
170
171.. option:: --wildcard, -w
172
173  Allow wildcard syntax for symbol-related flags. On by default for
174  section-related flags. Incompatible with --regex.
175
176  Wildcard syntax allows the following special symbols:
177
178  ====================== ========================= ==================
179   Character              Meaning                   Equivalent
180  ====================== ========================= ==================
181  ``*``                  Any number of characters  ``.*``
182  ``?``                  Any single character      ``.``
183  ``\``                  Escape the next character ``\``
184  ``[a-z]``              Character class           ``[a-z]``
185  ``[!a-z]``, ``[^a-z]`` Negated character class   ``[^a-z]``
186  ====================== ========================= ==================
187
188  Additionally, starting a wildcard with '!' will prevent a match, even if
189  another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols
190  except for ``x``.
191
192  The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is
193  the same as ``-w -N '!x' -N '*'``.
194
195COFF-SPECIFIC OPTIONS
196---------------------
197
198The following options are implemented only for COFF objects. If used with other
199objects, :program:`llvm-objcopy` will either emit an error or silently ignore
200them.
201
202ELF-SPECIFIC OPTIONS
203--------------------
204
205The following options are implemented only for ELF objects. If used with other
206objects, :program:`llvm-objcopy` will either emit an error or silently ignore
207them.
208
209.. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
210
211 Add a new symbol called ``<name>`` to the output symbol table, in the section
212 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
213 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
214 properties. Accepted values are:
215
216 - `global` = the symbol will have global binding.
217 - `local` = the symbol will have local binding.
218 - `weak` = the symbol will have weak binding.
219 - `default` = the symbol will have default visibility.
220 - `hidden` = the symbol will have hidden visibility.
221 - `protected` = the symbol will have protected visibility.
222 - `file` = the symbol will be an `STT_FILE` symbol.
223 - `section` = the symbol will be an `STT_SECTION` symbol.
224 - `object` = the symbol will be an `STT_OBJECT` symbol.
225 - `function` = the symbol will be an `STT_FUNC` symbol.
226 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
227
228 Additionally, the following flags are accepted but ignored: `debug`,
229 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
230
231 Can be specified multiple times to add multiple symbols.
232
233.. option:: --allow-broken-links
234
235 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
236 section references. Any invalid sh_link fields will be set to zero.
237
238.. option:: --build-id-link-dir <dir>
239
240 Set the directory used by :option:`--build-id-link-input` and
241 :option:`--build-id-link-output`.
242
243.. option:: --build-id-link-input <suffix>
244
245 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
246 specified by :option:`--build-id-link-dir`. The path used is derived from the
247 hex build ID.
248
249.. option:: --build-id-link-output <suffix>
250
251 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
252 specified by :option:`--build-id-link-dir`. The path used is derived from the
253 hex build ID.
254
255.. option:: --change-start <incr>, --adjust-start
256
257 Add ``<incr>`` to the program's start address. Can be specified multiple
258 times, in which case the values will be applied cumulatively.
259
260.. option:: --compress-debug-sections [<style>]
261
262 Compress DWARF debug sections in the output, using the specified style.
263 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
264 specified.
265
266.. option:: --decompress-debug-sections
267
268 Decompress any compressed DWARF debug sections in the output.
269
270.. option:: --discard-locals, -X
271
272 Remove local symbols starting with ".L" from the output.
273
274.. option:: --dump-section <section>=<file>
275
276 Dump the contents of section ``<section>`` into the file ``<file>``. Can be
277 specified multiple times to dump multiple sections to different files.
278 ``<file>`` is unrelated to the input and output files provided to
279 :program:`llvm-objcopy` and as such the normal copying and editing
280 operations will still be performed. No operations are performed on the sections
281 prior to dumping them.
282
283.. option:: --extract-dwo
284
285 Remove all sections that are not DWARF .dwo sections from the output.
286
287.. option:: --extract-main-partition
288
289 Extract the main partition from the output.
290
291.. option:: --extract-partition <name>
292
293 Extract the named partition from the output.
294
295.. option:: --globalize-symbol <symbol>
296
297 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
298 Can be specified multiple times to mark multiple symbols.
299
300.. option:: --globalize-symbols <filename>
301
302 Read a list of names from the file ``<filename>`` and mark defined symbols with
303 those names as global in the output. In the file, each line represents a single
304 symbol, with leading and trailing whitespace ignored, as is anything following
305 a '#'. Can be specified multiple times to read names from multiple files.
306
307.. option:: --input-target <format>, -I
308
309 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
310 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
311 to determine the format automatically.
312
313.. option:: --keep-file-symbols
314
315 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
316
317.. option:: --keep-global-symbol <symbol>
318
319 Make all symbols local in the output, except for symbols with the name
320 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
321
322.. option:: --keep-global-symbols <filename>
323
324 Make all symbols local in the output, except for symbols named in the file
325 ``<filename>``. In the file, each line represents a single symbol, with leading
326 and trailing whitespace ignored, as is anything following a '#'. Can be
327 specified multiple times to read names from multiple files.
328
329.. option:: --keep-section <section>
330
331 When removing sections from the output, do not remove sections named
332 ``<section>``. Can be specified multiple times to keep multiple sections.
333
334.. option:: --keep-symbol <symbol>, -K
335
336 When removing symbols from the output, do not remove symbols named
337 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
338
339.. option:: --keep-symbols <filename>
340
341 When removing symbols from the output do not remove symbols named in the file
342 ``<filename>``. In the file, each line represents a single symbol, with leading
343 and trailing whitespace ignored, as is anything following a '#'. Can be
344 specified multiple times to read names from multiple files.
345
346.. option:: --localize-hidden
347
348 Make all symbols with hidden or internal visibility local in the output.
349
350.. option:: --localize-symbol <symbol>, -L
351
352 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
353 output. Can be specified multiple times to mark multiple symbols as local.
354
355.. option:: --localize-symbols <filename>
356
357 Read a list of names from the file ``<filename>`` and mark defined non-common
358 symbols with those names as local in the output. In the file, each line
359 represents a single symbol, with leading and trailing whitespace ignored, as is
360 anything following a '#'. Can be specified multiple times to read names from
361 multiple files.
362
363.. option:: --new-symbol-visibility <visibility>
364
365 Specify the visibility of the symbols automatically created when using binary
366 input or :option:`--add-symbol`. Valid options are:
367
368 - `default`
369 - `hidden`
370 - `internal`
371 - `protected`
372
373 The default is `default`.
374
375.. option:: --output-target <format>, -O
376
377 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
378 of valid ``<format>`` values. If unspecified, the output format is assumed to
379 be the same as the input file's format.
380
381.. option:: --prefix-alloc-sections <prefix>
382
383 Add ``<prefix>`` to the front of the names of all allocatable sections in the
384 output.
385
386.. option:: --prefix-symbols <prefix>
387
388 Add ``<prefix>`` to the front of every symbol name in the output.
389
390.. option:: --preserve-dates, -p
391
392 Preserve access and modification timestamps in the output.
393
394.. option:: --rename-section <old>=<new>[,<flag>,...]
395
396 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
397 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
398 supported flags. Can be specified multiple times to rename multiple sections.
399
400.. option:: --set-section-flags <section>=<flag>[,<flag>,...]
401
402 Set section properties in the output of section ``<section>`` based on the
403 specified ``<flag>`` values. Can be specified multiple times to update multiple
404 sections.
405
406 Following is a list of supported flags and their effects:
407
408 - `alloc` = add the `SHF_ALLOC` flag.
409 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
410   section.
411 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
412 - `code` = add the `SHF_EXECINSTR` flag.
413 - `merge` = add the `SHF_MERGE` flag.
414 - `strings` = add the `SHF_STRINGS` flag.
415 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
416   section.
417
418 The following flags are also accepted, but are ignored for GNU compatibility:
419 `noload`, `debug`, `data`, `rom`, `share`.
420
421.. option:: --set-start-addr <addr>
422
423 Set the start address of the output to ``<addr>``. Overrides any previously
424 specified :option:`--change-start` or :option:`--adjust-start` options.
425
426.. option:: --split-dwo <dwo-file>
427
428 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
429 ``<dwo-file>`` as the output file and no other options, and then with
430 :option:`--strip-dwo` on the input file.
431
432.. option:: --strip-dwo
433
434 Remove all DWARF .dwo sections from the output.
435
436.. option:: --strip-non-alloc
437
438 Remove from the output all non-allocatable sections that are not within
439 segments.
440
441.. option:: --strip-sections
442
443 Remove from the output all section headers and all section data not within
444 segments. Note that many tools will not be able to use an object without
445 section headers.
446
447.. option:: --target <format>, -F
448
449 Equivalent to :option:`--input-target` and :option:`--output-target` for the
450 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
451 values.
452
453.. option:: --weaken-symbol <symbol>, -W
454
455 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
456 be specified multiple times to mark multiple symbols as weak.
457
458.. option:: --weaken-symbols <filename>
459
460 Read a list of names from the file ``<filename>`` and mark global symbols with
461 those names as weak in the output. In the file, each line represents a single
462 symbol, with leading and trailing whitespace ignored, as is anything following
463 a '#'. Can be specified multiple times to read names from multiple files.
464
465.. option:: --weaken
466
467 Mark all defined global symbols as weak in the output.
468
469SUPPORTED FORMATS
470-----------------
471
472The following values are currently supported by :program:`llvm-objcopy` for the
473:option:`--input-target`, :option:`--output-target`, and :option:`--target`
474options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
475
476- `binary`
477- `ihex`
478- `elf32-i386`
479- `elf32-x86-64`
480- `elf64-x86-64`
481- `elf32-iamcu`
482- `elf32-littlearm`
483- `elf64-aarch64`
484- `elf64-littleaarch64`
485- `elf32-littleriscv`
486- `elf64-littleriscv`
487- `elf32-powerpc`
488- `elf32-powerpcle`
489- `elf64-powerpc`
490- `elf64-powerpcle`
491- `elf32-bigmips`
492- `elf32-ntradbigmips`
493- `elf32-ntradlittlemips`
494- `elf32-tradbigmips`
495- `elf32-tradlittlemips`
496- `elf64-tradbigmips`
497- `elf64-tradlittlemips`
498- `elf32-sparc`
499- `elf32-sparcel`
500
501Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
502suffix.
503
504BINARY INPUT AND OUTPUT
505-----------------------
506
507If `binary` is used as the value for :option:`--input-target`, the input file
508will be embedded as a data section in an ELF relocatable object, with symbols
509``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
510``_binary_<file_name>_size`` representing the start, end and size of the data,
511where ``<file_name>`` is the path of the input file as specified on the command
512line with non-alphanumeric characters converted to ``_``.
513
514If `binary` is used as the value for :option:`--output-target`, the output file
515will be a raw binary file, containing the memory image of the input file.
516Symbols and relocation information will be discarded. The image will start at
517the address of the first loadable section in the output.
518
519EXIT STATUS
520-----------
521
522:program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
523Otherwise, it exits with code 0.
524
525BUGS
526----
527
528To report bugs, please visit <http://llvm.org/bugs/>.
529
530There is a known issue with :option:`--input-target` and :option:`--target`
531causing only ``binary`` and ``ihex`` formats to have any effect. Other values
532will be ignored and :program:`llvm-objcopy` will attempt to guess the input
533format.
534
535SEE ALSO
536--------
537
538:manpage:`llvm-strip(1)`
539