1 llvm-objcopy - object copying and editing tool
2 ==============================================
4 .. program:: llvm-objcopy
9 :program:`llvm-objcopy` [*options*] *input* [*output*]
14 :program:`llvm-objcopy` is a tool to copy and manipulate objects. In basic
15 usage, it makes a semantic copy of the input to the output. If any options are
16 specified, the output may be modified along the way, e.g. by removing sections.
18 If no output file is specified, the input file is modified in-place. If "-" is
19 specified for the input file, the input is read from the program's standard
20 input stream. If "-" is specified for the output file, the output is written to
21 the standard output stream of the program.
23 If the input is an archive, any requested operations will be applied to each
24 archive member individually.
26 The tool is still in active development, but in most scenarios it works as a
27 drop-in replacement for GNU's :program:`objcopy`.
29 GENERIC AND CROSS-PLATFORM OPTIONS
30 ----------------------------------
32 The following options are either agnostic of the file format, or apply to
33 multiple file formats.
35 .. option:: --add-gnu-debuglink <debug-file>
37 Add a .gnu_debuglink section for ``<debug-file>`` to the output.
39 .. option:: --add-section <section=file>
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.
46 For MachO objects, ``<section>`` must be formatted as
47 ``<segment name>,<section name>``.
49 .. option:: --binary-architecture <arch>, -B
51 Ignored for compatibility.
53 .. option:: --disable-deterministic-archives, -U
55 Use real values for UIDs, GIDs and timestamps when updating archive member
58 .. option:: --discard-all, -x
60 Remove most local symbols from the output. Different file formats may limit
61 this to a subset of the local symbols. For example, file and section symbols in
62 ELF objects will not be discarded. Additionally, remove all debug sections.
64 .. option:: --dump-section <section>=<file>
66 Dump the contents of section ``<section>`` into the file ``<file>``. Can be
67 specified multiple times to dump multiple sections to different files.
68 ``<file>`` is unrelated to the input and output files provided to
69 :program:`llvm-objcopy` and as such the normal copying and editing
70 operations will still be performed. No operations are performed on the sections
71 prior to dumping them.
73 For MachO objects, ``<section>`` must be formatted as
74 ``<segment name>,<section name>``.
76 .. option:: --enable-deterministic-archives, -D
78 Enable deterministic mode when copying archives, i.e. use 0 for archive member
79 header UIDs, GIDs and timestamp fields. On by default.
81 .. option:: --globalize-symbol <symbol>
83 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
84 Can be specified multiple times to mark multiple symbols.
86 .. option:: --globalize-symbols <filename>
88 Read a list of names from the file ``<filename>`` and mark defined symbols with
89 those names as global in the output. In the file, each line represents a single
90 symbol, with leading and trailing whitespace ignored, as is anything following
91 a '#'. Can be specified multiple times to read names from multiple files.
93 .. option:: --help, -h
95 Print a summary of command line options.
97 .. option:: --keep-global-symbol <symbol>, -G
99 Mark all symbols local in the output, except for symbols with the name
100 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
102 .. option:: --keep-global-symbols <filename>
104 Mark all symbols local in the output, except for symbols named in the file
105 ``<filename>``. In the file, each line represents a single symbol, with leading
106 and trailing whitespace ignored, as is anything following a '#'. Can be
107 specified multiple times to read names from multiple files.
109 .. option:: --localize-symbol <symbol>, -L
111 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
112 output. Can be specified multiple times to mark multiple symbols as local.
114 .. option:: --localize-symbols <filename>
116 Read a list of names from the file ``<filename>`` and mark defined non-common
117 symbols with those names as local in the output. In the file, each line
118 represents a single symbol, with leading and trailing whitespace ignored, as is
119 anything following a '#'. Can be specified multiple times to read names from
122 .. option:: --only-keep-debug
124 Produce a debug file as the output that only preserves contents of sections
125 useful for debugging purposes.
127 For ELF objects, this removes the contents of `SHF_ALLOC` sections that are not
128 `SHT_NOTE` by making them `SHT_NOBITS` and shrinking the program headers where
131 .. option:: --only-section <section>, -j
133 Remove all sections from the output, except for sections named ``<section>``.
134 Can be specified multiple times to keep multiple sections.
136 For MachO objects, ``<section>`` must be formatted as
137 ``<segment name>,<section name>``.
139 .. option:: --redefine-sym <old>=<new>
141 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
142 multiple times to rename multiple symbols.
144 .. option:: --redefine-syms <filename>
146 Rename symbols in the output as described in the file ``<filename>``. In the
147 file, each line represents a single symbol to rename, with the old name and new
148 name separated by whitespace. Leading and trailing whitespace is ignored, as is
149 anything following a '#'. Can be specified multiple times to read names from
154 If specified, symbol and section names specified by other switches are treated
155 as extended POSIX regular expression patterns.
157 .. option:: --remove-symbol-prefix <prefix>
159 Remove ``<prefix>`` from the start of every symbol name. No-op for symbols that do
160 not start with ``<prefix>``.
162 .. option:: --remove-section <section>, -R
164 Remove the specified section from the output. Can be specified multiple times
165 to remove multiple sections simultaneously.
167 For MachO objects, ``<section>`` must be formatted as
168 ``<segment name>,<section name>``.
170 .. option:: --set-section-alignment <section>=<align>
172 Set the alignment of section ``<section>`` to ``<align>``. Can be specified
173 multiple times to update multiple sections.
175 .. option:: --set-section-flags <section>=<flag>[,<flag>,...]
177 Set section properties in the output of section ``<section>`` based on the
178 specified ``<flag>`` values. Can be specified multiple times to update multiple
181 Supported flag names are `alloc`, `load`, `noload`, `readonly`, `exclude`,
182 `debug`, `code`, `data`, `rom`, `share`, `contents`, `merge`, `strings`, and
183 `large`. Not all flags are meaningful for all object file formats or target
186 For ELF objects, the flags have the following effects:
188 - `alloc` = add the `SHF_ALLOC` flag.
189 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
191 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
192 - `exclude` = add the `SHF_EXCLUDE` flag.
193 - `code` = add the `SHF_EXECINSTR` flag.
194 - `merge` = add the `SHF_MERGE` flag.
195 - `strings` = add the `SHF_STRINGS` flag.
196 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
198 - `large` = add the `SHF_X86_64_LARGE` on x86_64; rejected if the target
199 architecture is not x86_64.
201 For COFF objects, the flags have the following effects:
203 - `alloc` = add the `IMAGE_SCN_CNT_UNINITIALIZED_DATA` and `IMAGE_SCN_MEM_READ`
204 flags, unless the `load` flag is specified.
205 - `noload` = add the `IMAGE_SCN_LNK_REMOVE` and `IMAGE_SCN_MEM_READ` flags.
206 - `readonly` = if this flag is not specified, add the `IMAGE_SCN_MEM_WRITE`
208 - `exclude` = add the `IMAGE_SCN_LNK_REMOVE` and `IMAGE_SCN_MEM_READ` flags.
209 - `debug` = add the `IMAGE_SCN_CNT_INITIALIZED_DATA`,
210 `IMAGE_SCN_MEM_DISCARDABLE` and `IMAGE_SCN_MEM_READ` flags.
211 - `code` = add the `IMAGE_SCN_CNT_CODE`, `IMAGE_SCN_MEM_EXECUTE` and
212 `IMAGE_SCN_MEM_READ` flags.
213 - `data` = add the `IMAGE_SCN_CNT_INITIALIZED_DATA` and `IMAGE_SCN_MEM_READ`
215 - `share` = add the `IMAGE_SCN_MEM_SHARED` and `IMAGE_SCN_MEM_READ` flags.
217 .. option:: --skip-symbol <symbol>
219 Do not change the parameters of symbol ``<symbol>`` when executing other
220 options that can change the symbol's name, binding or visibility.
222 .. option:: --skip-symbols <filename>
224 Do not change the parameters of symbols named in the file ``<filename>`` when
225 executing other options that can change the symbol's name, binding or
226 visibility. In the file, each line represents a single symbol, with leading
227 and trailing whitespace ignored, as is anything following a '#'.
228 Can be specified multiple times to read names from multiple files.
230 .. option:: --strip-all-gnu
232 Remove all symbols, debug sections and relocations from the output. This option
233 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
235 .. option:: --strip-all, -S
237 For ELF objects, remove from the output all symbols and non-alloc sections not
238 within segments, except for .gnu.warning, .ARM.attribute sections and the
241 For COFF and Mach-O objects, remove all symbols, debug sections, and
242 relocations from the output.
244 .. option:: --strip-debug, -g
246 Remove all debug sections from the output.
248 .. option:: --strip-symbol <symbol>, -N
250 Remove all symbols named ``<symbol>`` from the output. Can be specified
251 multiple times to remove multiple symbols.
253 .. option:: --strip-symbols <filename>
255 Remove all symbols whose names appear in the file ``<filename>``, from the
256 output. In the file, each line represents a single symbol name, with leading
257 and trailing whitespace ignored, as is anything following a '#'. Can be
258 specified multiple times to read names from multiple files.
260 .. option:: --strip-unneeded-symbol <symbol>
262 Remove from the output all symbols named ``<symbol>`` that are local or
263 undefined and are not required by any relocation.
265 .. option:: --strip-unneeded-symbols <filename>
267 Remove all symbols whose names appear in the file ``<filename>``, from the
268 output, if they are local or undefined and are not required by any relocation.
269 In the file, each line represents a single symbol name, with leading and
270 trailing whitespace ignored, as is anything following a '#'. Can be specified
271 multiple times to read names from multiple files.
273 .. option:: --strip-unneeded
275 Remove from the output all local or undefined symbols that are not required by
276 relocations. Also remove all debug sections.
278 .. option:: --update-section <name>=<file>
280 Replace the contents of the section ``<name>`` with contents from the file
281 ``<file>``. If the section ``<name>`` is part of a segment, the new contents
282 cannot be larger than the existing section.
284 .. option:: --version, -V
286 Display the version of the :program:`llvm-objcopy` executable.
288 .. option:: --wildcard, -w
290 Allow wildcard syntax for symbol-related flags. On by default for
291 section-related flags. Incompatible with --regex.
293 Wildcard syntax allows the following special symbols:
295 ====================== ========================= ==================
296 Character Meaning Equivalent
297 ====================== ========================= ==================
298 ``*`` Any number of characters ``.*``
299 ``?`` Any single character ``.``
300 ``\`` Escape the next character ``\``
301 ``[a-z]`` Character class ``[a-z]``
302 ``[!a-z]``, ``[^a-z]`` Negated character class ``[^a-z]``
303 ====================== ========================= ==================
305 Additionally, starting a wildcard with '!' will prevent a match, even if
306 another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols
309 The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is
310 the same as ``-w -N '!x' -N '*'``.
314 Read command-line options and commands from response file `<FILE>`.
319 The following options are implemented only for ELF objects. If used with other
320 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
323 .. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
325 Add a new symbol called ``<name>`` to the output symbol table, in the section
326 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
327 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
328 properties. Accepted values are:
330 - `global` = the symbol will have global binding.
331 - `local` = the symbol will have local binding.
332 - `weak` = the symbol will have weak binding.
333 - `default` = the symbol will have default visibility.
334 - `hidden` = the symbol will have hidden visibility.
335 - `protected` = the symbol will have protected visibility.
336 - `file` = the symbol will be an `STT_FILE` symbol.
337 - `section` = the symbol will be an `STT_SECTION` symbol.
338 - `object` = the symbol will be an `STT_OBJECT` symbol.
339 - `function` = the symbol will be an `STT_FUNC` symbol.
340 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
342 Additionally, the following flags are accepted but ignored: `debug`,
343 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
345 Can be specified multiple times to add multiple symbols.
347 .. option:: --allow-broken-links
349 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
350 section references. Any invalid sh_link fields will be set to zero.
352 .. option:: --change-section-lma \*{+-}<val>
354 Shift LMA of non-zero-sized segments by ``<val>``.
356 .. option:: --change-section-address <section>{=+-}<val>, --adjust-section-vma
358 Change the address of sections that match ``<section>`` pattern to the
359 specified value, or apply ``+<val>``/``-<val>`` to the current value. Can be
360 specified multiple times to specify multiple patterns. Each section is only
361 modified by one ``--change-section-address`` argument. If a section name
362 matches multiple patterns, the rightmost change applies. The object file needs
363 to be of ET_REL type.
365 .. option:: --change-start <incr>, --adjust-start
367 Add ``<incr>`` to the program's start address. Can be specified multiple
368 times, in which case the values will be applied cumulatively.
370 .. option:: --compress-debug-sections [<format>]
372 Compress DWARF debug sections in the output, using the specified format.
373 Supported formats are ``zlib`` and ``zstd``. Use ``zlib`` if ``<format>`` is omitted.
375 .. option:: --compress-sections <section>=<format>
377 Compress or decompress sections matched by ``<section>`` using the specified
378 format. Supported formats are ``zlib`` and ``zstd``. Specify ``none`` for
379 decompression. When a section is matched by multiple options, the last one
380 wins. A wildcard ``<section>`` starting with '!' is disallowed.
381 Sections within a segment cannot be (de)compressed.
383 .. option:: --decompress-debug-sections
385 Decompress any compressed DWARF debug sections in the output.
387 .. option:: --discard-locals, -X
389 Remove local symbols starting with ".L" from the output.
391 .. option:: --extract-dwo
393 Remove all sections that are not DWARF .dwo sections from the output.
395 .. option:: --extract-main-partition
397 Extract the main partition from the output.
399 .. option:: --extract-partition <name>
401 Extract the named partition from the output.
403 .. option:: --gap-fill <value>
405 For binary outputs, fill the gaps between sections with ``<value>`` instead
406 of zero. The value must be an unsigned 8-bit integer.
408 .. option:: --input-target <format>, -I
410 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
411 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
412 to determine the format automatically.
414 .. option:: --keep-file-symbols
416 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
418 .. option:: --keep-section <section>
420 When removing sections from the output, do not remove sections named
421 ``<section>``. Can be specified multiple times to keep multiple sections.
423 .. option:: --keep-symbol <symbol>, -K
425 When removing symbols from the output, do not remove symbols named
426 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
428 .. option:: --keep-symbols <filename>
430 When removing symbols from the output do not remove symbols named in the file
431 ``<filename>``. In the file, each line represents a single symbol, with leading
432 and trailing whitespace ignored, as is anything following a '#'. Can be
433 specified multiple times to read names from multiple files.
435 .. option:: --localize-hidden
437 Mark all symbols with hidden or internal visibility local in the output.
439 .. option:: --new-symbol-visibility <visibility>
441 Specify the visibility of the symbols automatically created when using binary
442 input or :option:`--add-symbol`. Valid options are:
449 The default is `default`.
451 .. option:: --no-verify-note-sections
453 When adding note sections, do not verify if the section format is valid.
455 .. option:: --output-target <format>, -O
457 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
458 of valid ``<format>`` values. If unspecified, the output format is assumed to
459 be the same as the value specified for :option:`--input-target` or the input
460 file's format if that option is also unspecified.
462 .. option:: --pad-to <address>
464 For binary outputs, pad the output to the load address ``<address>`` using a value
465 of zero or the value specified by :option:`--gap-fill`.
467 .. option:: --prefix-alloc-sections <prefix>
469 Add ``<prefix>`` to the front of the names of all allocatable sections in the
472 .. option:: --prefix-symbols <prefix>
474 Add ``<prefix>`` to the front of every symbol name in the output.
476 .. option:: --preserve-dates, -p
478 Preserve access and modification timestamps in the output.
480 .. option:: --rename-section <old>=<new>[,<flag>,...]
482 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
483 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
484 supported flags. Can be specified multiple times to rename multiple sections.
486 .. option:: --set-section-type <section>=<type>
488 Set the type of section ``<section>`` to the integer ``<type>``. Can be
489 specified multiple times to update multiple sections.
491 .. option:: --set-start <addr>
493 Set the start address of the output to ``<addr>``. Overrides any previously
494 specified :option:`--change-start` or :option:`--adjust-start` options.
496 .. option:: --set-symbol-visibility <symbol>=<visibility>
498 Change the visibility of a symbol to the specified value.
500 .. option:: --set-symbols-visibility <filename>=<visibility>
502 Read a list of symbols from <filename> and change their visibility to the
503 specified value. Visibility values: default, internal, hidden, protected.
505 .. option:: --split-dwo <dwo-file>
507 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
508 ``<dwo-file>`` as the output file and no other options, and then with
509 :option:`--strip-dwo` on the input file.
511 .. option:: --strip-dwo
513 Remove all DWARF .dwo sections from the output.
515 .. option:: --strip-non-alloc
517 Remove from the output all non-allocatable sections that are not within
520 .. option:: --strip-sections
522 Remove from the output all section headers and all section data not within
523 segments. Note that many tools will not be able to use an object without
526 .. option:: --target <format>, -F
528 Equivalent to :option:`--input-target` and :option:`--output-target` for the
529 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
532 .. option:: --verify-note-sections
534 When adding note sections, verify if the section format is valid. On by
537 .. option:: --weaken-symbol <symbol>, -W
539 Mark global symbols named ``<symbol>`` as weak symbols in the output. Can
540 be specified multiple times to mark multiple symbols as weak.
542 .. option:: --weaken-symbols <filename>
544 Read a list of names from the file ``<filename>`` and mark global symbols with
545 those names as weak in the output. In the file, each line represents a single
546 symbol, with leading and trailing whitespace ignored, as is anything following
547 a '#'. Can be specified multiple times to read names from multiple files.
551 Mark all defined global symbols as weak in the output.
553 MACH-O-SPECIFIC OPTIONS
554 -----------------------
556 .. option:: --keep-undefined
558 Keep undefined symbols, even if they would otherwise be stripped.
560 COFF-SPECIFIC OPTIONS
561 ---------------------
563 .. option:: --subsystem <name>[:<version>]
565 Set the PE subsystem, and optionally subsystem version.
570 The following values are currently supported by :program:`llvm-objcopy` for the
571 :option:`--input-target`, :option:`--output-target`, and :option:`--target`
572 options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
582 - `elf64-littleaarch64`
583 - `elf32-littleriscv`
584 - `elf64-littleriscv`
590 - `elf32-ntradbigmips`
591 - `elf32-ntradlittlemips`
592 - `elf32-tradbigmips`
593 - `elf32-tradlittlemips`
594 - `elf64-tradbigmips`
595 - `elf64-tradlittlemips`
603 The following formats are suppoprted by :program:`llvm-objcopy` for the
604 :option:`--output-target` only:
608 Additionally, all targets except `binary`, `ihex`, and `srec` can have
609 `-freebsd` as a suffix.
611 BINARY INPUT AND OUTPUT
612 -----------------------
614 If `binary` is used as the value for :option:`--input-target`, the input file
615 will be embedded as a data section in an ELF relocatable object, with symbols
616 ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
617 ``_binary_<file_name>_size`` representing the start, end and size of the data,
618 where ``<file_name>`` is the path of the input file as specified on the command
619 line with non-alphanumeric characters converted to ``_``.
621 If `binary` is used as the value for :option:`--output-target`, the output file
622 will be a raw binary file, containing the memory image of the input file.
623 Symbols and relocation information will be discarded. The image will start at
624 the address of the first loadable section in the output.
629 :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
630 Otherwise, it exits with code 0.
635 To report bugs, please visit <https://github.com/llvm/llvm-project/labels/tools:llvm-objcopy/strip/>.
637 There is a known issue with :option:`--input-target` and :option:`--target`
638 causing only ``binary`` and ``ihex`` formats to have any effect. Other values
639 will be ignored and :program:`llvm-objcopy` will attempt to guess the input
645 :manpage:`llvm-strip(1)`