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.
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:: --strip-all-gnu
135 Remove all symbols, debug sections and relocations from the output. This option
136 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
138 .. option:: --strip-all, -S
140 For ELF objects, remove from the output all symbols and non-alloc sections not
141 within segments, except for .gnu.warning, .ARM.attribute sections and the
144 For COFF and Mach-O objects, remove all symbols, debug sections, and
145 relocations from the output.
147 .. option:: --strip-debug, -g
149 Remove all debug sections from the output.
151 .. option:: --strip-symbol <symbol>, -N
153 Remove all symbols named ``<symbol>`` from the output. Can be specified
154 multiple times to remove multiple symbols.
156 .. option:: --strip-symbols <filename>
158 Remove all symbols whose names appear in the file ``<filename>``, from the
159 output. In the file, each line represents a single symbol name, with leading
160 and trailing whitespace ignored, as is anything following a '#'. Can be
161 specified multiple times to read names from multiple files.
163 .. option:: --strip-unneeded-symbol <symbol>
165 Remove from the output all symbols named ``<symbol>`` that are local or
166 undefined and are not required by any relocation.
168 .. option:: --strip-unneeded-symbols <filename>
170 Remove all symbols whose names appear in the file ``<filename>``, from the
171 output, if they are local or undefined and are not required by any relocation.
172 In the file, each line represents a single symbol name, with leading and
173 trailing whitespace ignored, as is anything following a '#'. Can be specified
174 multiple times to read names from multiple files.
176 .. option:: --strip-unneeded
178 Remove from the output all local or undefined symbols that are not required by
179 relocations. Also remove all debug sections.
181 .. option:: --version, -V
183 Display the version of the :program:`llvm-objcopy` executable.
187 Read command-line options and commands from response file `<FILE>`.
189 .. option:: --wildcard, -w
191 Allow wildcard syntax for symbol-related flags. On by default for
192 section-related flags. Incompatible with --regex.
194 Wildcard syntax allows the following special symbols:
196 ====================== ========================= ==================
197 Character Meaning Equivalent
198 ====================== ========================= ==================
199 ``*`` Any number of characters ``.*``
200 ``?`` Any single character ``.``
201 ``\`` Escape the next character ``\``
202 ``[a-z]`` Character class ``[a-z]``
203 ``[!a-z]``, ``[^a-z]`` Negated character class ``[^a-z]``
204 ====================== ========================= ==================
206 Additionally, starting a wildcard with '!' will prevent a match, even if
207 another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols
210 The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is
211 the same as ``-w -N '!x' -N '*'``.
213 COFF-SPECIFIC OPTIONS
214 ---------------------
216 The following options are implemented only for COFF objects. If used with other
217 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
223 The following options are implemented only for ELF objects. If used with other
224 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
227 .. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
229 Add a new symbol called ``<name>`` to the output symbol table, in the section
230 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
231 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
232 properties. Accepted values are:
234 - `global` = the symbol will have global binding.
235 - `local` = the symbol will have local binding.
236 - `weak` = the symbol will have weak binding.
237 - `default` = the symbol will have default visibility.
238 - `hidden` = the symbol will have hidden visibility.
239 - `protected` = the symbol will have protected visibility.
240 - `file` = the symbol will be an `STT_FILE` symbol.
241 - `section` = the symbol will be an `STT_SECTION` symbol.
242 - `object` = the symbol will be an `STT_OBJECT` symbol.
243 - `function` = the symbol will be an `STT_FUNC` symbol.
244 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
246 Additionally, the following flags are accepted but ignored: `debug`,
247 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
249 Can be specified multiple times to add multiple symbols.
251 .. option:: --allow-broken-links
253 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
254 section references. Any invalid sh_link fields will be set to zero.
256 .. option:: --build-id-link-dir <dir>
258 Set the directory used by :option:`--build-id-link-input` and
259 :option:`--build-id-link-output`.
261 .. option:: --build-id-link-input <suffix>
263 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
264 specified by :option:`--build-id-link-dir`. The path used is derived from the
267 .. option:: --build-id-link-output <suffix>
269 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
270 specified by :option:`--build-id-link-dir`. The path used is derived from the
273 .. option:: --change-start <incr>, --adjust-start
275 Add ``<incr>`` to the program's start address. Can be specified multiple
276 times, in which case the values will be applied cumulatively.
278 .. option:: --compress-debug-sections [<style>]
280 Compress DWARF debug sections in the output, using the specified style.
281 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
284 .. option:: --decompress-debug-sections
286 Decompress any compressed DWARF debug sections in the output.
288 .. option:: --discard-locals, -X
290 Remove local symbols starting with ".L" from the output.
292 .. option:: --extract-dwo
294 Remove all sections that are not DWARF .dwo sections from the output.
296 .. option:: --extract-main-partition
298 Extract the main partition from the output.
300 .. option:: --extract-partition <name>
302 Extract the named partition from the output.
304 .. option:: --globalize-symbol <symbol>
306 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
307 Can be specified multiple times to mark multiple symbols.
309 .. option:: --globalize-symbols <filename>
311 Read a list of names from the file ``<filename>`` and mark defined symbols with
312 those names as global in the output. In the file, each line represents a single
313 symbol, with leading and trailing whitespace ignored, as is anything following
314 a '#'. Can be specified multiple times to read names from multiple files.
316 .. option:: --input-target <format>, -I
318 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
319 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
320 to determine the format automatically.
322 .. option:: --keep-file-symbols
324 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
326 .. option:: --keep-global-symbol <symbol>
328 Make all symbols local in the output, except for symbols with the name
329 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
331 .. option:: --keep-global-symbols <filename>
333 Make all symbols local in the output, except for symbols named in the file
334 ``<filename>``. In the file, each line represents a single symbol, with leading
335 and trailing whitespace ignored, as is anything following a '#'. Can be
336 specified multiple times to read names from multiple files.
338 .. option:: --keep-section <section>
340 When removing sections from the output, do not remove sections named
341 ``<section>``. Can be specified multiple times to keep multiple sections.
343 .. option:: --keep-symbol <symbol>, -K
345 When removing symbols from the output, do not remove symbols named
346 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
348 .. option:: --keep-symbols <filename>
350 When removing symbols from the output do not remove symbols named in the file
351 ``<filename>``. In the file, each line represents a single symbol, with leading
352 and trailing whitespace ignored, as is anything following a '#'. Can be
353 specified multiple times to read names from multiple files.
355 .. option:: --localize-hidden
357 Make all symbols with hidden or internal visibility local in the output.
359 .. option:: --localize-symbol <symbol>, -L
361 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
362 output. Can be specified multiple times to mark multiple symbols as local.
364 .. option:: --localize-symbols <filename>
366 Read a list of names from the file ``<filename>`` and mark defined non-common
367 symbols with those names as local in the output. In the file, each line
368 represents a single symbol, with leading and trailing whitespace ignored, as is
369 anything following a '#'. Can be specified multiple times to read names from
372 .. option:: --new-symbol-visibility <visibility>
374 Specify the visibility of the symbols automatically created when using binary
375 input or :option:`--add-symbol`. Valid options are:
382 The default is `default`.
384 .. option:: --output-target <format>, -O
386 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
387 of valid ``<format>`` values. If unspecified, the output format is assumed to
388 be the same as the input file's format.
390 .. option:: --prefix-alloc-sections <prefix>
392 Add ``<prefix>`` to the front of the names of all allocatable sections in the
395 .. option:: --prefix-symbols <prefix>
397 Add ``<prefix>`` to the front of every symbol name in the output.
399 .. option:: --preserve-dates, -p
401 Preserve access and modification timestamps in the output.
403 .. option:: --rename-section <old>=<new>[,<flag>,...]
405 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
406 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
407 supported flags. Can be specified multiple times to rename multiple sections.
409 .. option:: --set-section-flags <section>=<flag>[,<flag>,...]
411 Set section properties in the output of section ``<section>`` based on the
412 specified ``<flag>`` values. Can be specified multiple times to update multiple
415 Following is a list of supported flags and their effects:
417 - `alloc` = add the `SHF_ALLOC` flag.
418 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
420 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
421 - `exclude` = add the `SHF_EXCLUDE` flag.
422 - `code` = add the `SHF_EXECINSTR` flag.
423 - `merge` = add the `SHF_MERGE` flag.
424 - `strings` = add the `SHF_STRINGS` flag.
425 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
428 The following flags are also accepted, but are ignored for GNU compatibility:
429 `noload`, `debug`, `data`, `rom`, `share`.
431 .. option:: --set-start-addr <addr>
433 Set the start address of the output to ``<addr>``. Overrides any previously
434 specified :option:`--change-start` or :option:`--adjust-start` options.
436 .. option:: --split-dwo <dwo-file>
438 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
439 ``<dwo-file>`` as the output file and no other options, and then with
440 :option:`--strip-dwo` on the input file.
442 .. option:: --strip-dwo
444 Remove all DWARF .dwo sections from the output.
446 .. option:: --strip-non-alloc
448 Remove from the output all non-allocatable sections that are not within
451 .. option:: --strip-sections
453 Remove from the output all section headers and all section data not within
454 segments. Note that many tools will not be able to use an object without
457 .. option:: --target <format>, -F
459 Equivalent to :option:`--input-target` and :option:`--output-target` for the
460 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
463 .. option:: --weaken-symbol <symbol>, -W
465 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
466 be specified multiple times to mark multiple symbols as weak.
468 .. option:: --weaken-symbols <filename>
470 Read a list of names from the file ``<filename>`` and mark global symbols with
471 those names as weak in the output. In the file, each line represents a single
472 symbol, with leading and trailing whitespace ignored, as is anything following
473 a '#'. Can be specified multiple times to read names from multiple files.
477 Mark all defined global symbols as weak in the output.
482 The following values are currently supported by :program:`llvm-objcopy` for the
483 :option:`--input-target`, :option:`--output-target`, and :option:`--target`
484 options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
494 - `elf64-littleaarch64`
495 - `elf32-littleriscv`
496 - `elf64-littleriscv`
502 - `elf32-ntradbigmips`
503 - `elf32-ntradlittlemips`
504 - `elf32-tradbigmips`
505 - `elf32-tradlittlemips`
506 - `elf64-tradbigmips`
507 - `elf64-tradlittlemips`
511 Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
514 BINARY INPUT AND OUTPUT
515 -----------------------
517 If `binary` is used as the value for :option:`--input-target`, the input file
518 will be embedded as a data section in an ELF relocatable object, with symbols
519 ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
520 ``_binary_<file_name>_size`` representing the start, end and size of the data,
521 where ``<file_name>`` is the path of the input file as specified on the command
522 line with non-alphanumeric characters converted to ``_``.
524 If `binary` is used as the value for :option:`--output-target`, the output file
525 will be a raw binary file, containing the memory image of the input file.
526 Symbols and relocation information will be discarded. The image will start at
527 the address of the first loadable section in the output.
532 :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
533 Otherwise, it exits with code 0.
538 To report bugs, please visit <http://llvm.org/bugs/>.
540 There is a known issue with :option:`--input-target` and :option:`--target`
541 causing only ``binary`` and ``ihex`` formats to have any effect. Other values
542 will be ignored and :program:`llvm-objcopy` will attempt to guess the input
548 :manpage:`llvm-strip(1)`