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` and `strings`. Not
141 all flags are meaningful for all object file formats.
143 For ELF objects, the flags have the following effects:
145 - `alloc` = add the `SHF_ALLOC` flag.
146 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
148 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
149 - `exclude` = add the `SHF_EXCLUDE` flag.
150 - `code` = add the `SHF_EXECINSTR` flag.
151 - `merge` = add the `SHF_MERGE` flag.
152 - `strings` = add the `SHF_STRINGS` flag.
153 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
156 For COFF objects, the flags have the following effects:
158 - `alloc` = add the `IMAGE_SCN_CNT_UNINITIALIZED_DATA` and `IMAGE_SCN_MEM_READ`
159 flags, unless the `load` flag is specified.
160 - `noload` = add the `IMAGE_SCN_LNK_REMOVE` and `IMAGE_SCN_MEM_READ` flags.
161 - `readonly` = if this flag is not specified, add the `IMAGE_SCN_MEM_WRITE`
163 - `exclude` = add the `IMAGE_SCN_LNK_REMOVE` and `IMAGE_SCN_MEM_READ` flags.
164 - `debug` = add the `IMAGE_SCN_CNT_INITIALIZED_DATA`,
165 `IMAGE_SCN_MEM_DISCARDABLE` and `IMAGE_SCN_MEM_READ` flags.
166 - `code` = add the `IMAGE_SCN_CNT_CODE`, `IMAGE_SCN_MEM_EXECUTE` and
167 `IMAGE_SCN_MEM_READ` flags.
168 - `data` = add the `IMAGE_SCN_CNT_INITIALIZED_DATA` and `IMAGE_SCN_MEM_READ`
170 - `share` = add the `IMAGE_SCN_MEM_SHARED` and `IMAGE_SCN_MEM_READ` flags.
172 .. option:: --strip-all-gnu
174 Remove all symbols, debug sections and relocations from the output. This option
175 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
177 .. option:: --strip-all, -S
179 For ELF objects, remove from the output all symbols and non-alloc sections not
180 within segments, except for .gnu.warning, .ARM.attribute sections and the
183 For COFF and Mach-O objects, remove all symbols, debug sections, and
184 relocations from the output.
186 .. option:: --strip-debug, -g
188 Remove all debug sections from the output.
190 .. option:: --strip-symbol <symbol>, -N
192 Remove all symbols named ``<symbol>`` from the output. Can be specified
193 multiple times to remove multiple symbols.
195 .. option:: --strip-symbols <filename>
197 Remove all symbols whose names appear in the file ``<filename>``, from the
198 output. In the file, each line represents a single symbol name, with leading
199 and trailing whitespace ignored, as is anything following a '#'. Can be
200 specified multiple times to read names from multiple files.
202 .. option:: --strip-unneeded-symbol <symbol>
204 Remove from the output all symbols named ``<symbol>`` that are local or
205 undefined and are not required by any relocation.
207 .. option:: --strip-unneeded-symbols <filename>
209 Remove all symbols whose names appear in the file ``<filename>``, from the
210 output, if they are local or undefined and are not required by any relocation.
211 In the file, each line represents a single symbol name, with leading and
212 trailing whitespace ignored, as is anything following a '#'. Can be specified
213 multiple times to read names from multiple files.
215 .. option:: --strip-unneeded
217 Remove from the output all local or undefined symbols that are not required by
218 relocations. Also remove all debug sections.
220 .. option:: --version, -V
222 Display the version of the :program:`llvm-objcopy` executable.
224 .. option:: --wildcard, -w
226 Allow wildcard syntax for symbol-related flags. On by default for
227 section-related flags. Incompatible with --regex.
229 Wildcard syntax allows the following special symbols:
231 ====================== ========================= ==================
232 Character Meaning Equivalent
233 ====================== ========================= ==================
234 ``*`` Any number of characters ``.*``
235 ``?`` Any single character ``.``
236 ``\`` Escape the next character ``\``
237 ``[a-z]`` Character class ``[a-z]``
238 ``[!a-z]``, ``[^a-z]`` Negated character class ``[^a-z]``
239 ====================== ========================= ==================
241 Additionally, starting a wildcard with '!' will prevent a match, even if
242 another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols
245 The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is
246 the same as ``-w -N '!x' -N '*'``.
250 Read command-line options and commands from response file `<FILE>`.
255 The following options are implemented only for ELF objects. If used with other
256 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
259 .. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
261 Add a new symbol called ``<name>`` to the output symbol table, in the section
262 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
263 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
264 properties. Accepted values are:
266 - `global` = the symbol will have global binding.
267 - `local` = the symbol will have local binding.
268 - `weak` = the symbol will have weak binding.
269 - `default` = the symbol will have default visibility.
270 - `hidden` = the symbol will have hidden visibility.
271 - `protected` = the symbol will have protected visibility.
272 - `file` = the symbol will be an `STT_FILE` symbol.
273 - `section` = the symbol will be an `STT_SECTION` symbol.
274 - `object` = the symbol will be an `STT_OBJECT` symbol.
275 - `function` = the symbol will be an `STT_FUNC` symbol.
276 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
278 Additionally, the following flags are accepted but ignored: `debug`,
279 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
281 Can be specified multiple times to add multiple symbols.
283 .. option:: --allow-broken-links
285 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
286 section references. Any invalid sh_link fields will be set to zero.
288 .. option:: --change-start <incr>, --adjust-start
290 Add ``<incr>`` to the program's start address. Can be specified multiple
291 times, in which case the values will be applied cumulatively.
293 .. option:: --compress-debug-sections [<style>]
295 Compress DWARF debug sections in the output, using the specified style.
296 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
299 .. option:: --decompress-debug-sections
301 Decompress any compressed DWARF debug sections in the output.
303 .. option:: --discard-locals, -X
305 Remove local symbols starting with ".L" from the output.
307 .. option:: --extract-dwo
309 Remove all sections that are not DWARF .dwo sections from the output.
311 .. option:: --extract-main-partition
313 Extract the main partition from the output.
315 .. option:: --extract-partition <name>
317 Extract the named partition from the output.
319 .. option:: --globalize-symbol <symbol>
321 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
322 Can be specified multiple times to mark multiple symbols.
324 .. option:: --globalize-symbols <filename>
326 Read a list of names from the file ``<filename>`` and mark defined symbols with
327 those names as global in the output. In the file, each line represents a single
328 symbol, with leading and trailing whitespace ignored, as is anything following
329 a '#'. Can be specified multiple times to read names from multiple files.
331 .. option:: --input-target <format>, -I
333 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
334 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
335 to determine the format automatically.
337 .. option:: --keep-file-symbols
339 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
341 .. option:: --keep-global-symbol <symbol>, -G
343 Make all symbols local in the output, except for symbols with the name
344 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
346 .. option:: --keep-global-symbols <filename>
348 Make all symbols local in the output, except for symbols named in the file
349 ``<filename>``. In the file, each line represents a single symbol, with leading
350 and trailing whitespace ignored, as is anything following a '#'. Can be
351 specified multiple times to read names from multiple files.
353 .. option:: --keep-section <section>
355 When removing sections from the output, do not remove sections named
356 ``<section>``. Can be specified multiple times to keep multiple sections.
358 .. option:: --keep-symbol <symbol>, -K
360 When removing symbols from the output, do not remove symbols named
361 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
363 .. option:: --keep-symbols <filename>
365 When removing symbols from the output do not remove symbols named in the file
366 ``<filename>``. In the file, each line represents a single symbol, with leading
367 and trailing whitespace ignored, as is anything following a '#'. Can be
368 specified multiple times to read names from multiple files.
370 .. option:: --localize-hidden
372 Make all symbols with hidden or internal visibility local in the output.
374 .. option:: --localize-symbol <symbol>, -L
376 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
377 output. Can be specified multiple times to mark multiple symbols as local.
379 .. option:: --localize-symbols <filename>
381 Read a list of names from the file ``<filename>`` and mark defined non-common
382 symbols with those names as local in the output. In the file, each line
383 represents a single symbol, with leading and trailing whitespace ignored, as is
384 anything following a '#'. Can be specified multiple times to read names from
387 .. option:: --new-symbol-visibility <visibility>
389 Specify the visibility of the symbols automatically created when using binary
390 input or :option:`--add-symbol`. Valid options are:
397 The default is `default`.
399 .. option:: --output-target <format>, -O
401 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
402 of valid ``<format>`` values. If unspecified, the output format is assumed to
403 be the same as the value specified for :option:`--input-target` or the input
404 file's format if that option is also unspecified.
406 .. option:: --prefix-alloc-sections <prefix>
408 Add ``<prefix>`` to the front of the names of all allocatable sections in the
411 .. option:: --prefix-symbols <prefix>
413 Add ``<prefix>`` to the front of every symbol name in the output.
415 .. option:: --preserve-dates, -p
417 Preserve access and modification timestamps in the output.
419 .. option:: --rename-section <old>=<new>[,<flag>,...]
421 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
422 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
423 supported flags. Can be specified multiple times to rename multiple sections.
425 .. option:: --set-start-addr <addr>
427 Set the start address of the output to ``<addr>``. Overrides any previously
428 specified :option:`--change-start` or :option:`--adjust-start` options.
430 .. option:: --split-dwo <dwo-file>
432 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
433 ``<dwo-file>`` as the output file and no other options, and then with
434 :option:`--strip-dwo` on the input file.
436 .. option:: --strip-dwo
438 Remove all DWARF .dwo sections from the output.
440 .. option:: --strip-non-alloc
442 Remove from the output all non-allocatable sections that are not within
445 .. option:: --strip-sections
447 Remove from the output all section headers and all section data not within
448 segments. Note that many tools will not be able to use an object without
451 .. option:: --target <format>, -F
453 Equivalent to :option:`--input-target` and :option:`--output-target` for the
454 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
457 .. option:: --weaken-symbol <symbol>, -W
459 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
460 be specified multiple times to mark multiple symbols as weak.
462 .. option:: --weaken-symbols <filename>
464 Read a list of names from the file ``<filename>`` and mark global symbols with
465 those names as weak in the output. In the file, each line represents a single
466 symbol, with leading and trailing whitespace ignored, as is anything following
467 a '#'. Can be specified multiple times to read names from multiple files.
471 Mark all defined global symbols as weak in the output.
473 MACH-O-SPECIFIC OPTIONS
474 -----------------------
476 .. option:: --keep-undefined
478 Keep undefined symbols, even if they would otherwise be stripped.
483 The following values are currently supported by :program:`llvm-objcopy` for the
484 :option:`--input-target`, :option:`--output-target`, and :option:`--target`
485 options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
495 - `elf64-littleaarch64`
496 - `elf32-littleriscv`
497 - `elf64-littleriscv`
503 - `elf32-ntradbigmips`
504 - `elf32-ntradlittlemips`
505 - `elf32-tradbigmips`
506 - `elf32-tradlittlemips`
507 - `elf64-tradbigmips`
508 - `elf64-tradlittlemips`
512 Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
515 BINARY INPUT AND OUTPUT
516 -----------------------
518 If `binary` is used as the value for :option:`--input-target`, the input file
519 will be embedded as a data section in an ELF relocatable object, with symbols
520 ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
521 ``_binary_<file_name>_size`` representing the start, end and size of the data,
522 where ``<file_name>`` is the path of the input file as specified on the command
523 line with non-alphanumeric characters converted to ``_``.
525 If `binary` is used as the value for :option:`--output-target`, the output file
526 will be a raw binary file, containing the memory image of the input file.
527 Symbols and relocation information will be discarded. The image will start at
528 the address of the first loadable section in the output.
533 :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
534 Otherwise, it exits with code 0.
539 To report bugs, please visit <https://bugs.llvm.org/>.
541 There is a known issue with :option:`--input-target` and :option:`--target`
542 causing only ``binary`` and ``ihex`` formats to have any effect. Other values
543 will be ignored and :program:`llvm-objcopy` will attempt to guess the input
549 :manpage:`llvm-strip(1)`