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 .. option:: --disable-deterministic-archives, -U
48 Use real values for UIDs, GIDs and timestamps when updating archive member
51 .. option:: --discard-all, -x
53 Remove most local symbols from the output. Different file formats may limit
54 this to a subset of the local symbols. For example, file and section symbols in
55 ELF objects will not be discarded.
57 .. option:: --enable-deterministic-archives, -D
59 Enable deterministic mode when copying archives, i.e. use 0 for archive member
60 header UIDs, GIDs and timestamp fields. On by default.
62 .. option:: --help, -h
64 Print a summary of command line options.
66 .. option:: --only-section <section>, -j
68 Remove all sections from the output, except for sections named ``<section>``.
69 Can be specified multiple times to keep multiple sections.
73 If specified, symbol and section names specified by other switches are treated
74 as extended POSIX regular expression patterns.
76 .. option:: --remove-section <section>, -R
78 Remove the specified section from the output. Can be specified multiple times
79 to remove multiple sections simultaneously.
81 .. option:: --strip-all-gnu
83 Remove all symbols, debug sections and relocations from the output. This option
84 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
86 .. option:: --strip-all, -S
88 For ELF objects, remove from the output all symbols and non-alloc sections not
89 within segments, except for .gnu.warning sections and the section name table.
91 For COFF objects, remove all symbols, debug sections, and relocations from the
94 .. option:: --strip-debug, -g
96 Remove all debug sections from the output.
98 .. option:: --strip-symbol <symbol>, -N
100 Remove all symbols named ``<symbol>`` from the output. Can be specified
101 multiple times to remove multiple symbols.
103 .. option:: --strip-symbols <filename>
105 Remove all symbols whose names appear in the file ``<filename>``, from the
106 output. In the file, each line represents a single symbol name, with leading
107 and trailing whitespace ignored, as is anything following a '#'. Can be
108 specified multiple times to read names from multiple files.
110 .. option:: --strip-unneeded-symbol <symbol>
112 Remove from the output all symbols named ``<symbol>`` that are local or
113 undefined and are not required by any relocation.
115 .. option:: --strip-unneeded-symbols <filename>
117 Remove all symbols whose names appear in the file ``<filename>``, from the
118 output, if they are local or undefined and are not required by any relocation.
119 In the file, each line represents a single symbol name, with leading and
120 trailing whitespace ignored, as is anything following a '#'. Can be specified
121 multiple times to read names from multiple files.
123 .. option:: --strip-unneeded
125 Remove from the output all local or undefined symbols that are not required by
128 .. option:: --version, -V
130 Display the version of this program.
132 COFF-SPECIFIC OPTIONS
133 ---------------------
135 The following options are implemented only for COFF objects. If used with other
136 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
139 .. option:: --only-keep-debug
141 Remove the contents of non-debug sections from the output, but keep the section
147 The following options are implemented only for ELF objects. If used with other
148 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
151 .. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
153 Add a new symbol called ``<name>`` to the output symbol table, in the section
154 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
155 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
156 properties. Accepted values are:
158 - `global` = the symbol will have global binding.
159 - `local` = the symbol will have local binding.
160 - `weak` = the symbol will have weak binding.
161 - `default` = the symbol will have default visibility.
162 - `hidden` = the symbol will have hidden visibility.
163 - `protected` = the symbol will have protected visibility.
164 - `file` = the symbol will be an `STT_FILE` symbol.
165 - `section` = the symbol will be an `STT_SECTION` symbol.
166 - `object` = the symbol will be an `STT_OBJECT` symbol.
167 - `function` = the symbol will be an `STT_FUNC` symbol.
168 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
170 Additionally, the following flags are accepted but ignored: `debug`,
171 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
173 Can be specified multiple times to add multiple symbols.
175 .. option:: --allow-broken-links
177 Allow llvm-objcopy to remove sections even if it would leave invalid section
178 references. Any invalid sh_link fields will be set to zero.
180 .. option:: --binary-architecture <arch>, -B
182 Specify the architecture to use, when transforming an architecture-less format
183 (e.g. binary) to another format. Valid options are:
197 .. option:: --build-id-link-dir <dir>
199 Set the directory used by :option:`--build-id-link-input` and
200 :option:`--build-id-link-output`.
202 .. option:: --build-id-link-input <suffix>
204 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
205 specified by :option:`--build-id-link-dir`. The path used is derived from the
208 .. option:: --build-id-link-output <suffix>
210 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
211 specified by :option:`--build-id-link-dir`. The path used is derived from the
214 .. option:: --change-start <incr>, --adjust-start
216 Add ``<incr>`` to the program's start address. Can be specified multiple
217 times, in which case the values will be applied cumulatively.
219 .. option:: --compress-debug-sections [<style>]
221 Compress DWARF debug sections in the output, using the specified style.
222 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
225 .. option:: --decompress-debug-sections
227 Decompress any compressed DWARF debug sections in the output.
229 .. option:: --discard-locals, -X
231 Remove local symbols starting with ".L" from the output.
233 .. option:: --dump-section <section>=<file>
235 Dump the contents of section ``<section>`` into the file ``<file>``. Can be
236 specified multiple times to dump multiple sections to different files.
237 ``<file>`` is unrelated to the input and output files provided to
238 :program:`llvm-objcopy` and as such the normal copying and editing
239 operations will still be performed. No operations are performed on the sections
240 prior to dumping them.
242 .. option:: --extract-dwo
244 Remove all sections that are not DWARF .dwo sections from the output.
246 .. option:: --extract-main-partition
248 Extract the main partition from the output.
250 .. option:: --extract-partition <name>
252 Extract the named partition from the output.
254 .. option:: --globalize-symbol <symbol>
256 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
257 Can be specified multiple times to mark multiple symbols.
259 .. option:: --globalize-symbols <filename>
261 Read a list of names from the file ``<filename>`` and mark defined symbols with
262 those names as global in the output. In the file, each line represents a single
263 symbol, with leading and trailing whitespace ignored, as is anything following
264 a '#'. Can be specified multiple times to read names from multiple files.
266 .. option:: --input-target <format>, -I
268 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
269 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
270 to determine the format automatically.
272 .. option:: --keep-file-symbols
274 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
276 .. option:: --keep-global-symbol <symbol>
278 Make all symbols local in the output, except for symbols with the name
279 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
281 .. option:: --keep-global-symbols <filename>
283 Make all symbols local in the output, except for symbols named in the file
284 ``<filename>``. In the file, each line represents a single symbol, with leading
285 and trailing whitespace ignored, as is anything following a '#'. Can be
286 specified multiple times to read names from multiple files.
288 .. option:: --keep-section <section>
290 When removing sections from the output, do not remove sections named
291 ``<section>``. Can be specified multiple times to keep multiple sections.
293 .. option:: --keep-symbol <symbol>, -K
295 When removing symbols from the output, do not remove symbols named
296 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
298 .. option:: --keep-symbols <filename>
300 When removing symbols from the output do not remove symbols named in the file
301 ``<filename>``. In the file, each line represents a single symbol, with leading
302 and trailing whitespace ignored, as is anything following a '#'. Can be
303 specified multiple times to read names from multiple files.
305 .. option:: --localize-hidden
307 Make all symbols with hidden or internal visibility local in the output.
309 .. option:: --localize-symbol <symbol>, -L
311 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
312 output. Can be specified multiple times to mark multiple symbols as local.
314 .. option:: --localize-symbols <filename>
316 Read a list of names from the file ``<filename>`` and mark defined non-common
317 symbols with those names as local in the output. In the file, each line
318 represents a single symbol, with leading and trailing whitespace ignored, as is
319 anything following a '#'. Can be specified multiple times to read names from
322 .. option:: --new-symbol-visibility <visibility>
324 Specify the visibility of the symbols automatically created when using binary
325 input or :option:`--add-symbol`. Valid options are:
332 The default is `default`.
334 .. option:: --output-target <format>, -O
336 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
337 of valid ``<format>`` values. If unspecified, the output format is assumed to
338 be the same as the input file's format.
340 .. option:: --prefix-alloc-sections <prefix>
342 Add ``<prefix>`` to the front of the names of all allocatable sections in the
345 .. option:: --prefix-symbols <prefix>
347 Add ``<prefix>`` to the front of every symbol name in the output.
349 .. option:: --preserve-dates, -p
351 Preserve access and modification timestamps in the output.
353 .. option:: --redefine-sym <old>=<new>
355 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
356 multiple times to rename multiple symbols.
358 .. option:: --redefine-syms <filename>
360 Rename symbols in the output as described in the file ``<filename>``. In the
361 file, each line represents a single symbol to rename, with the old name and new
362 name separated by an equals sign. Leading and trailing whitespace is ignored,
363 as is anything following a '#'. Can be specified multiple times to read names
366 .. option:: --rename-section <old>=<new>[,<flag>,...]
368 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
369 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
370 supported flags. Can be specified multiple times to rename multiple sections.
372 .. option:: --set-section-flags <section>=<flag>[,<flag>,...]
374 Set section properties in the output of section ``<section>`` based on the
375 specified ``<flag>`` values. Can be specified multiple times to update multiple
378 Following is a list of supported flags and their effects:
380 - `alloc` = add the `SHF_ALLOC` flag.
381 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
383 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
384 - `code` = add the `SHF_EXECINSTR` flag.
385 - `merge` = add the `SHF_MERGE` flag.
386 - `strings` = add the `SHF_STRINGS` flag.
387 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
390 The following flags are also accepted, but are ignored for GNU compatibility:
391 `noload`, `debug`, `data`, `rom`, `share`.
393 .. option:: --set-start-addr <addr>
395 Set the start address of the output to ``<addr>``. Overrides any previously
396 specified :option:`--change-start` or :option:`--adjust-start` options.
398 .. option:: --split-dwo <dwo-file>
400 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
401 ``<dwo-file>`` as the output file and no other options, and then with
402 :option:`--strip-dwo` on the input file.
404 .. option:: --strip-dwo
406 Remove all DWARF .dwo sections from the output.
408 .. option:: --strip-non-alloc
410 Remove from the output all non-allocatable sections that are not within
413 .. option:: --strip-sections
415 Remove from the output all section headers and all section data not within
416 segments. Note that many tools will not be able to use an object without
419 .. option:: --target <format>, -F
421 Equivalent to :option:`--input-target` and :option:`--output-target` for the
422 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
425 .. option:: --weaken-symbol <symbol>, -W
427 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
428 be specified multiple times to mark multiple symbols as weak.
430 .. option:: --weaken-symbols <filename>
432 Read a list of names from the file ``<filename>`` and mark global symbols with
433 those names as weak in the output. In the file, each line represents a single
434 symbol, with leading and trailing whitespace ignored, as is anything following
435 a '#'. Can be specified multiple times to read names from multiple files.
439 Mark all defined global symbols as weak in the output.
444 The following values are currently supported by :program:`llvm-objcopy` for the
445 :option:`--input-target`, :option:`--output-target`, and :option:`--target`
446 options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
456 - `elf64-littleaarch64`
457 - `elf32-littleriscv`
458 - `elf64-littleriscv`
464 - `elf32-ntradbigmips`
465 - `elf32-ntradlittlemips`
466 - `elf32-tradbigmips`
467 - `elf32-tradlittlemips`
468 - `elf64-tradbigmips`
469 - `elf64-tradlittlemips`
473 Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
476 BINARY INPUT AND OUTPUT
477 -----------------------
479 If `binary` is used as the value for :option:`--input-target`, the input file
480 will be embedded as a data section in an ELF relocatable object, with symbols
481 ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
482 ``_binary_<file_name>_size`` representing the start, end and size of the data,
483 where ``<file_name>`` is the path of the input file as specified on the command
484 line with non-alphanumeric characters converted to ``_``.
486 If `binary` is used as the value for :option:`--output-target`, the output file
487 will be a raw binary file, containing the memory image of the input file.
488 Symbols and relocation information will be discarded. The image will start at
489 the address of the first loadable section in the output.
494 :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
495 Otherwise, it exits with code 0.
500 To report bugs, please visit <http://llvm.org/bugs/>.
502 There is a known issue with :option:`--input-target` and :option:`--target`
503 causing only ``binary`` and ``ihex`` formats to have any effect. Other values
504 will be ignored and :program:`llvm-objcopy` will attempt to guess the input
510 :manpage:`llvm-strip(1)`