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:: --help, -h
83 Print a summary of command line options.
85 .. option:: --only-keep-debug
87 Produce a debug file as the output that only preserves contents of sections
88 useful for debugging purposes.
90 For ELF objects, this removes the contents of `SHF_ALLOC` sections that are not
91 `SHT_NOTE` by making them `SHT_NOBITS` and shrinking the program headers where
94 .. option:: --only-section <section>, -j
96 Remove all sections from the output, except for sections named ``<section>``.
97 Can be specified multiple times to keep multiple sections.
99 For MachO objects, ``<section>`` must be formatted as
100 ``<segment name>,<section name>``.
102 .. option:: --redefine-sym <old>=<new>
104 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
105 multiple times to rename multiple symbols.
107 .. option:: --redefine-syms <filename>
109 Rename symbols in the output as described in the file ``<filename>``. In the
110 file, each line represents a single symbol to rename, with the old name and new
111 name separated by whitespace. Leading and trailing whitespace is ignored, as is
112 anything following a '#'. Can be specified multiple times to read names from
117 If specified, symbol and section names specified by other switches are treated
118 as extended POSIX regular expression patterns.
120 .. option:: --remove-section <section>, -R
122 Remove the specified section from the output. Can be specified multiple times
123 to remove multiple sections simultaneously.
125 For MachO objects, ``<section>`` must be formatted as
126 ``<segment name>,<section name>``.
128 .. option:: --set-section-alignment <section>=<align>
130 Set the alignment of section ``<section>`` to ``<align>``. Can be specified
131 multiple times to update multiple sections.
133 .. option:: --set-section-flags <section>=<flag>[,<flag>,...]
135 Set section properties in the output of section ``<section>`` based on the
136 specified ``<flag>`` values. Can be specified multiple times to update multiple
139 Supported flag names are `alloc`, `load`, `noload`, `readonly`, `exclude`,
140 `debug`, `code`, `data`, `rom`, `share`, `contents`, `merge`, `strings`, and
141 `large`. Not all flags are meaningful for all object file formats or target
144 For ELF objects, the flags have the following effects:
146 - `alloc` = add the `SHF_ALLOC` flag.
147 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
149 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
150 - `exclude` = add the `SHF_EXCLUDE` flag.
151 - `code` = add the `SHF_EXECINSTR` flag.
152 - `merge` = add the `SHF_MERGE` flag.
153 - `strings` = add the `SHF_STRINGS` flag.
154 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
156 - `large` = add the `SHF_X86_64_LARGE` on x86_64; rejected if the target
157 architecture is not x86_64.
159 For COFF objects, the flags have the following effects:
161 - `alloc` = add the `IMAGE_SCN_CNT_UNINITIALIZED_DATA` and `IMAGE_SCN_MEM_READ`
162 flags, unless the `load` flag is specified.
163 - `noload` = add the `IMAGE_SCN_LNK_REMOVE` and `IMAGE_SCN_MEM_READ` flags.
164 - `readonly` = if this flag is not specified, add the `IMAGE_SCN_MEM_WRITE`
166 - `exclude` = add the `IMAGE_SCN_LNK_REMOVE` and `IMAGE_SCN_MEM_READ` flags.
167 - `debug` = add the `IMAGE_SCN_CNT_INITIALIZED_DATA`,
168 `IMAGE_SCN_MEM_DISCARDABLE` and `IMAGE_SCN_MEM_READ` flags.
169 - `code` = add the `IMAGE_SCN_CNT_CODE`, `IMAGE_SCN_MEM_EXECUTE` and
170 `IMAGE_SCN_MEM_READ` flags.
171 - `data` = add the `IMAGE_SCN_CNT_INITIALIZED_DATA` and `IMAGE_SCN_MEM_READ`
173 - `share` = add the `IMAGE_SCN_MEM_SHARED` and `IMAGE_SCN_MEM_READ` flags.
175 .. option:: --strip-all-gnu
177 Remove all symbols, debug sections and relocations from the output. This option
178 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
180 .. option:: --strip-all, -S
182 For ELF objects, remove from the output all symbols and non-alloc sections not
183 within segments, except for .gnu.warning, .ARM.attribute sections and the
186 For COFF and Mach-O objects, remove all symbols, debug sections, and
187 relocations from the output.
189 .. option:: --strip-debug, -g
191 Remove all debug sections from the output.
193 .. option:: --strip-symbol <symbol>, -N
195 Remove all symbols named ``<symbol>`` from the output. Can be specified
196 multiple times to remove multiple symbols.
198 .. option:: --strip-symbols <filename>
200 Remove all symbols whose names appear in the file ``<filename>``, from the
201 output. In the file, each line represents a single symbol name, with leading
202 and trailing whitespace ignored, as is anything following a '#'. Can be
203 specified multiple times to read names from multiple files.
205 .. option:: --strip-unneeded-symbol <symbol>
207 Remove from the output all symbols named ``<symbol>`` that are local or
208 undefined and are not required by any relocation.
210 .. option:: --strip-unneeded-symbols <filename>
212 Remove all symbols whose names appear in the file ``<filename>``, from the
213 output, if they are local or undefined and are not required by any relocation.
214 In the file, each line represents a single symbol name, with leading and
215 trailing whitespace ignored, as is anything following a '#'. Can be specified
216 multiple times to read names from multiple files.
218 .. option:: --strip-unneeded
220 Remove from the output all local or undefined symbols that are not required by
221 relocations. Also remove all debug sections.
223 .. option:: --update-section <name>=<file>
225 Replace the contents of the section ``<name>`` with contents from the file
226 ``<file>``. If the section ``<name>`` is part of a segment, the new contents
227 cannot be larger than the existing section.
229 .. option:: --version, -V
231 Display the version of the :program:`llvm-objcopy` executable.
233 .. option:: --wildcard, -w
235 Allow wildcard syntax for symbol-related flags. On by default for
236 section-related flags. Incompatible with --regex.
238 Wildcard syntax allows the following special symbols:
240 ====================== ========================= ==================
241 Character Meaning Equivalent
242 ====================== ========================= ==================
243 ``*`` Any number of characters ``.*``
244 ``?`` Any single character ``.``
245 ``\`` Escape the next character ``\``
246 ``[a-z]`` Character class ``[a-z]``
247 ``[!a-z]``, ``[^a-z]`` Negated character class ``[^a-z]``
248 ====================== ========================= ==================
250 Additionally, starting a wildcard with '!' will prevent a match, even if
251 another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols
254 The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is
255 the same as ``-w -N '!x' -N '*'``.
259 Read command-line options and commands from response file `<FILE>`.
264 The following options are implemented only for ELF objects. If used with other
265 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
268 .. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
270 Add a new symbol called ``<name>`` to the output symbol table, in the section
271 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
272 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
273 properties. Accepted values are:
275 - `global` = the symbol will have global binding.
276 - `local` = the symbol will have local binding.
277 - `weak` = the symbol will have weak binding.
278 - `default` = the symbol will have default visibility.
279 - `hidden` = the symbol will have hidden visibility.
280 - `protected` = the symbol will have protected visibility.
281 - `file` = the symbol will be an `STT_FILE` symbol.
282 - `section` = the symbol will be an `STT_SECTION` symbol.
283 - `object` = the symbol will be an `STT_OBJECT` symbol.
284 - `function` = the symbol will be an `STT_FUNC` symbol.
285 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
287 Additionally, the following flags are accepted but ignored: `debug`,
288 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
290 Can be specified multiple times to add multiple symbols.
292 .. option:: --allow-broken-links
294 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
295 section references. Any invalid sh_link fields will be set to zero.
297 .. option:: --change-start <incr>, --adjust-start
299 Add ``<incr>`` to the program's start address. Can be specified multiple
300 times, in which case the values will be applied cumulatively.
302 .. option:: --compress-debug-sections [<format>]
304 Compress DWARF debug sections in the output, using the specified format.
305 Supported formats are ``zlib`` and ``zstd``. Use ``zlib`` if ``<format>`` is omitted.
307 .. option:: --decompress-debug-sections
309 Decompress any compressed DWARF debug sections in the output.
311 .. option:: --discard-locals, -X
313 Remove local symbols starting with ".L" from the output.
315 .. option:: --extract-dwo
317 Remove all sections that are not DWARF .dwo sections from the output.
319 .. option:: --extract-main-partition
321 Extract the main partition from the output.
323 .. option:: --extract-partition <name>
325 Extract the named partition from the output.
327 .. option:: --gap-fill <value>
329 For binary outputs, fill the gaps between sections with ``<value>`` instead
330 of zero. The value must be an unsigned 8-bit integer.
332 .. option:: --globalize-symbol <symbol>
334 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
335 Can be specified multiple times to mark multiple symbols.
337 .. option:: --globalize-symbols <filename>
339 Read a list of names from the file ``<filename>`` and mark defined symbols with
340 those names as global in the output. In the file, each line represents a single
341 symbol, with leading and trailing whitespace ignored, as is anything following
342 a '#'. Can be specified multiple times to read names from multiple files.
344 .. option:: --input-target <format>, -I
346 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
347 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
348 to determine the format automatically.
350 .. option:: --keep-file-symbols
352 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
354 .. option:: --keep-global-symbol <symbol>, -G
356 Make all symbols local in the output, except for symbols with the name
357 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
359 .. option:: --keep-global-symbols <filename>
361 Make all symbols local in the output, except for symbols named in the file
362 ``<filename>``. In the file, each line represents a single symbol, with leading
363 and trailing whitespace ignored, as is anything following a '#'. Can be
364 specified multiple times to read names from multiple files.
366 .. option:: --keep-section <section>
368 When removing sections from the output, do not remove sections named
369 ``<section>``. Can be specified multiple times to keep multiple sections.
371 .. option:: --keep-symbol <symbol>, -K
373 When removing symbols from the output, do not remove symbols named
374 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
376 .. option:: --keep-symbols <filename>
378 When removing symbols from the output do not remove symbols named in the file
379 ``<filename>``. In the file, each line represents a single symbol, with leading
380 and trailing whitespace ignored, as is anything following a '#'. Can be
381 specified multiple times to read names from multiple files.
383 .. option:: --localize-hidden
385 Make all symbols with hidden or internal visibility local in the output.
387 .. option:: --localize-symbol <symbol>, -L
389 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
390 output. Can be specified multiple times to mark multiple symbols as local.
392 .. option:: --localize-symbols <filename>
394 Read a list of names from the file ``<filename>`` and mark defined non-common
395 symbols with those names as local in the output. In the file, each line
396 represents a single symbol, with leading and trailing whitespace ignored, as is
397 anything following a '#'. Can be specified multiple times to read names from
400 .. option:: --new-symbol-visibility <visibility>
402 Specify the visibility of the symbols automatically created when using binary
403 input or :option:`--add-symbol`. Valid options are:
410 The default is `default`.
412 .. option:: --output-target <format>, -O
414 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
415 of valid ``<format>`` values. If unspecified, the output format is assumed to
416 be the same as the value specified for :option:`--input-target` or the input
417 file's format if that option is also unspecified.
419 .. option:: --pad-to <address>
421 For binary outputs, pad the output to the load address ``<address>`` using a value
422 of zero or the value specified by :option:`--gap-fill`.
424 .. option:: --prefix-alloc-sections <prefix>
426 Add ``<prefix>`` to the front of the names of all allocatable sections in the
429 .. option:: --prefix-symbols <prefix>
431 Add ``<prefix>`` to the front of every symbol name in the output.
433 .. option:: --preserve-dates, -p
435 Preserve access and modification timestamps in the output.
437 .. option:: --rename-section <old>=<new>[,<flag>,...]
439 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
440 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
441 supported flags. Can be specified multiple times to rename multiple sections.
443 .. option:: --set-section-type <section>=<type>
445 Set the type of section ``<section>`` to the integer ``<type>``. Can be
446 specified multiple times to update multiple sections.
448 .. option:: --set-start-addr <addr>
450 Set the start address of the output to ``<addr>``. Overrides any previously
451 specified :option:`--change-start` or :option:`--adjust-start` options.
453 .. option:: --split-dwo <dwo-file>
455 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
456 ``<dwo-file>`` as the output file and no other options, and then with
457 :option:`--strip-dwo` on the input file.
459 .. option:: --strip-dwo
461 Remove all DWARF .dwo sections from the output.
463 .. option:: --strip-non-alloc
465 Remove from the output all non-allocatable sections that are not within
468 .. option:: --strip-sections
470 Remove from the output all section headers and all section data not within
471 segments. Note that many tools will not be able to use an object without
474 .. option:: --target <format>, -F
476 Equivalent to :option:`--input-target` and :option:`--output-target` for the
477 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
480 .. option:: --weaken-symbol <symbol>, -W
482 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
483 be specified multiple times to mark multiple symbols as weak.
485 .. option:: --weaken-symbols <filename>
487 Read a list of names from the file ``<filename>`` and mark global symbols with
488 those names as weak in the output. In the file, each line represents a single
489 symbol, with leading and trailing whitespace ignored, as is anything following
490 a '#'. Can be specified multiple times to read names from multiple files.
494 Mark all defined global symbols as weak in the output.
496 MACH-O-SPECIFIC OPTIONS
497 -----------------------
499 .. option:: --keep-undefined
501 Keep undefined symbols, even if they would otherwise be stripped.
503 COFF-SPECIFIC OPTIONS
504 ---------------------
506 .. option:: --subsystem <name>[:<version>]
508 Set the PE subsystem, and optionally subsystem version.
513 The following values are currently supported by :program:`llvm-objcopy` for the
514 :option:`--input-target`, :option:`--output-target`, and :option:`--target`
515 options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
525 - `elf64-littleaarch64`
526 - `elf32-littleriscv`
527 - `elf64-littleriscv`
533 - `elf32-ntradbigmips`
534 - `elf32-ntradlittlemips`
535 - `elf32-tradbigmips`
536 - `elf32-tradlittlemips`
537 - `elf64-tradbigmips`
538 - `elf64-tradlittlemips`
542 Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
545 BINARY INPUT AND OUTPUT
546 -----------------------
548 If `binary` is used as the value for :option:`--input-target`, the input file
549 will be embedded as a data section in an ELF relocatable object, with symbols
550 ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
551 ``_binary_<file_name>_size`` representing the start, end and size of the data,
552 where ``<file_name>`` is the path of the input file as specified on the command
553 line with non-alphanumeric characters converted to ``_``.
555 If `binary` is used as the value for :option:`--output-target`, the output file
556 will be a raw binary file, containing the memory image of the input file.
557 Symbols and relocation information will be discarded. The image will start at
558 the address of the first loadable section in the output.
563 :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
564 Otherwise, it exits with code 0.
569 To report bugs, please visit <https://github.com/llvm/llvm-project/labels/tools:llvm-objcopy/strip/>.
571 There is a known issue with :option:`--input-target` and :option:`--target`
572 causing only ``binary`` and ``ihex`` formats to have any effect. Other values
573 will be ignored and :program:`llvm-objcopy` will attempt to guess the input
579 :manpage:`llvm-strip(1)`