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:: --binary-architecture <arch>, -B
48 Ignored for compatibility.
50 .. option:: --disable-deterministic-archives, -U
52 Use real values for UIDs, GIDs and timestamps when updating archive member
55 .. option:: --discard-all, -x
57 Remove most local symbols from the output. Different file formats may limit
58 this to a subset of the local symbols. For example, file and section symbols in
59 ELF objects will not be discarded.
61 .. option:: --enable-deterministic-archives, -D
63 Enable deterministic mode when copying archives, i.e. use 0 for archive member
64 header UIDs, GIDs and timestamp fields. On by default.
66 .. option:: --help, -h
68 Print a summary of command line options.
70 .. option:: --only-section <section>, -j
72 Remove all sections from the output, except for sections named ``<section>``.
73 Can be specified multiple times to keep multiple sections.
77 If specified, symbol and section names specified by other switches are treated
78 as extended POSIX regular expression patterns.
80 .. option:: --remove-section <section>, -R
82 Remove the specified section from the output. Can be specified multiple times
83 to remove multiple sections simultaneously.
85 .. option:: --set-section-alignment <section>=<align>
87 Set the alignment of section ``<section>`` to `<align>``. Can be specified
88 multiple times to update multiple sections.
90 .. option:: --strip-all-gnu
92 Remove all symbols, debug sections and relocations from the output. This option
93 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
95 .. option:: --strip-all, -S
97 For ELF objects, remove from the output all symbols and non-alloc sections not
98 within segments, except for .gnu.warning sections and the section name table.
100 For COFF objects, remove all symbols, debug sections, and relocations from the
103 .. option:: --strip-debug, -g
105 Remove all debug sections from the output.
107 .. option:: --strip-symbol <symbol>, -N
109 Remove all symbols named ``<symbol>`` from the output. Can be specified
110 multiple times to remove multiple symbols.
112 .. option:: --strip-symbols <filename>
114 Remove all symbols whose names appear in the file ``<filename>``, from the
115 output. In the file, each line represents a single symbol name, with leading
116 and trailing whitespace ignored, as is anything following a '#'. Can be
117 specified multiple times to read names from multiple files.
119 .. option:: --strip-unneeded-symbol <symbol>
121 Remove from the output all symbols named ``<symbol>`` that are local or
122 undefined and are not required by any relocation.
124 .. option:: --strip-unneeded-symbols <filename>
126 Remove all symbols whose names appear in the file ``<filename>``, from the
127 output, if they are local or undefined and are not required by any relocation.
128 In the file, each line represents a single symbol name, with leading and
129 trailing whitespace ignored, as is anything following a '#'. Can be specified
130 multiple times to read names from multiple files.
132 .. option:: --strip-unneeded
134 Remove from the output all local or undefined symbols that are not required by
135 relocations. Also remove all debug sections.
137 .. option:: --version, -V
139 Display the version of the :program:`llvm-objcopy` executable.
143 Read command-line options and commands from response file `<FILE>`.
145 .. option:: --wildcard, -w
147 Allow wildcard syntax for symbol-related flags. On by default for
148 section-related flags. Incompatible with --regex.
150 Wildcard syntax allows the following special symbols:
152 ====================== ========================= ==================
153 Character Meaning Equivalent
154 ====================== ========================= ==================
155 ``*`` Any number of characters ``.*``
156 ``?`` Any single character ``.``
157 ``\`` Escape the next character ``\``
158 ``[a-z]`` Character class ``[a-z]``
159 ``[!a-z]``, ``[^a-z]`` Negated character class ``[^a-z]``
160 ====================== ========================= ==================
162 Additionally, starting a wildcard with '!' will prevent a match, even if
163 another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols
166 The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is
167 the same as ``-w -N '!x' -N '*'``.
169 COFF-SPECIFIC OPTIONS
170 ---------------------
172 The following options are implemented only for COFF objects. If used with other
173 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
176 .. option:: --only-keep-debug
178 Remove the contents of non-debug sections from the output, but keep the section
184 The following options are implemented only for ELF objects. If used with other
185 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
188 .. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
190 Add a new symbol called ``<name>`` to the output symbol table, in the section
191 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
192 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
193 properties. Accepted values are:
195 - `global` = the symbol will have global binding.
196 - `local` = the symbol will have local binding.
197 - `weak` = the symbol will have weak binding.
198 - `default` = the symbol will have default visibility.
199 - `hidden` = the symbol will have hidden visibility.
200 - `protected` = the symbol will have protected visibility.
201 - `file` = the symbol will be an `STT_FILE` symbol.
202 - `section` = the symbol will be an `STT_SECTION` symbol.
203 - `object` = the symbol will be an `STT_OBJECT` symbol.
204 - `function` = the symbol will be an `STT_FUNC` symbol.
205 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
207 Additionally, the following flags are accepted but ignored: `debug`,
208 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
210 Can be specified multiple times to add multiple symbols.
212 .. option:: --allow-broken-links
214 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
215 section references. Any invalid sh_link fields will be set to zero.
217 .. option:: --build-id-link-dir <dir>
219 Set the directory used by :option:`--build-id-link-input` and
220 :option:`--build-id-link-output`.
222 .. option:: --build-id-link-input <suffix>
224 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
225 specified by :option:`--build-id-link-dir`. The path used is derived from the
228 .. option:: --build-id-link-output <suffix>
230 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
231 specified by :option:`--build-id-link-dir`. The path used is derived from the
234 .. option:: --change-start <incr>, --adjust-start
236 Add ``<incr>`` to the program's start address. Can be specified multiple
237 times, in which case the values will be applied cumulatively.
239 .. option:: --compress-debug-sections [<style>]
241 Compress DWARF debug sections in the output, using the specified style.
242 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
245 .. option:: --decompress-debug-sections
247 Decompress any compressed DWARF debug sections in the output.
249 .. option:: --discard-locals, -X
251 Remove local symbols starting with ".L" from the output.
253 .. option:: --dump-section <section>=<file>
255 Dump the contents of section ``<section>`` into the file ``<file>``. Can be
256 specified multiple times to dump multiple sections to different files.
257 ``<file>`` is unrelated to the input and output files provided to
258 :program:`llvm-objcopy` and as such the normal copying and editing
259 operations will still be performed. No operations are performed on the sections
260 prior to dumping them.
262 .. option:: --extract-dwo
264 Remove all sections that are not DWARF .dwo sections from the output.
266 .. option:: --extract-main-partition
268 Extract the main partition from the output.
270 .. option:: --extract-partition <name>
272 Extract the named partition from the output.
274 .. option:: --globalize-symbol <symbol>
276 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
277 Can be specified multiple times to mark multiple symbols.
279 .. option:: --globalize-symbols <filename>
281 Read a list of names from the file ``<filename>`` and mark defined symbols with
282 those names as global in the output. In the file, each line represents a single
283 symbol, with leading and trailing whitespace ignored, as is anything following
284 a '#'. Can be specified multiple times to read names from multiple files.
286 .. option:: --input-target <format>, -I
288 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
289 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
290 to determine the format automatically.
292 .. option:: --keep-file-symbols
294 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
296 .. option:: --keep-global-symbol <symbol>
298 Make all symbols local in the output, except for symbols with the name
299 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
301 .. option:: --keep-global-symbols <filename>
303 Make all symbols local in the output, except for symbols named in the file
304 ``<filename>``. In the file, each line represents a single symbol, with leading
305 and trailing whitespace ignored, as is anything following a '#'. Can be
306 specified multiple times to read names from multiple files.
308 .. option:: --keep-section <section>
310 When removing sections from the output, do not remove sections named
311 ``<section>``. Can be specified multiple times to keep multiple sections.
313 .. option:: --keep-symbol <symbol>, -K
315 When removing symbols from the output, do not remove symbols named
316 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
318 .. option:: --keep-symbols <filename>
320 When removing symbols from the output do not remove symbols named in the file
321 ``<filename>``. In the file, each line represents a single symbol, with leading
322 and trailing whitespace ignored, as is anything following a '#'. Can be
323 specified multiple times to read names from multiple files.
325 .. option:: --localize-hidden
327 Make all symbols with hidden or internal visibility local in the output.
329 .. option:: --localize-symbol <symbol>, -L
331 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
332 output. Can be specified multiple times to mark multiple symbols as local.
334 .. option:: --localize-symbols <filename>
336 Read a list of names from the file ``<filename>`` and mark defined non-common
337 symbols with those names as local in the output. In the file, each line
338 represents a single symbol, with leading and trailing whitespace ignored, as is
339 anything following a '#'. Can be specified multiple times to read names from
342 .. option:: --new-symbol-visibility <visibility>
344 Specify the visibility of the symbols automatically created when using binary
345 input or :option:`--add-symbol`. Valid options are:
352 The default is `default`.
354 .. option:: --output-target <format>, -O
356 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
357 of valid ``<format>`` values. If unspecified, the output format is assumed to
358 be the same as the input file's format.
360 .. option:: --prefix-alloc-sections <prefix>
362 Add ``<prefix>`` to the front of the names of all allocatable sections in the
365 .. option:: --prefix-symbols <prefix>
367 Add ``<prefix>`` to the front of every symbol name in the output.
369 .. option:: --preserve-dates, -p
371 Preserve access and modification timestamps in the output.
373 .. option:: --redefine-sym <old>=<new>
375 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
376 multiple times to rename multiple symbols.
378 .. option:: --redefine-syms <filename>
380 Rename symbols in the output as described in the file ``<filename>``. In the
381 file, each line represents a single symbol to rename, with the old name and new
382 name separated by an equals sign. Leading and trailing whitespace is ignored,
383 as is anything following a '#'. Can be specified multiple times to read names
386 .. option:: --rename-section <old>=<new>[,<flag>,...]
388 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
389 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
390 supported flags. Can be specified multiple times to rename multiple sections.
392 .. option:: --set-section-flags <section>=<flag>[,<flag>,...]
394 Set section properties in the output of section ``<section>`` based on the
395 specified ``<flag>`` values. Can be specified multiple times to update multiple
398 Following is a list of supported flags and their effects:
400 - `alloc` = add the `SHF_ALLOC` flag.
401 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
403 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
404 - `code` = add the `SHF_EXECINSTR` flag.
405 - `merge` = add the `SHF_MERGE` flag.
406 - `strings` = add the `SHF_STRINGS` flag.
407 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
410 The following flags are also accepted, but are ignored for GNU compatibility:
411 `noload`, `debug`, `data`, `rom`, `share`.
413 .. option:: --set-start-addr <addr>
415 Set the start address of the output to ``<addr>``. Overrides any previously
416 specified :option:`--change-start` or :option:`--adjust-start` options.
418 .. option:: --split-dwo <dwo-file>
420 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
421 ``<dwo-file>`` as the output file and no other options, and then with
422 :option:`--strip-dwo` on the input file.
424 .. option:: --strip-dwo
426 Remove all DWARF .dwo sections from the output.
428 .. option:: --strip-non-alloc
430 Remove from the output all non-allocatable sections that are not within
433 .. option:: --strip-sections
435 Remove from the output all section headers and all section data not within
436 segments. Note that many tools will not be able to use an object without
439 .. option:: --target <format>, -F
441 Equivalent to :option:`--input-target` and :option:`--output-target` for the
442 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
445 .. option:: --weaken-symbol <symbol>, -W
447 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
448 be specified multiple times to mark multiple symbols as weak.
450 .. option:: --weaken-symbols <filename>
452 Read a list of names from the file ``<filename>`` and mark global symbols with
453 those names as weak in the output. In the file, each line represents a single
454 symbol, with leading and trailing whitespace ignored, as is anything following
455 a '#'. Can be specified multiple times to read names from multiple files.
459 Mark all defined global symbols as weak in the output.
464 The following values are currently supported by :program:`llvm-objcopy` for the
465 :option:`--input-target`, :option:`--output-target`, and :option:`--target`
466 options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
476 - `elf64-littleaarch64`
477 - `elf32-littleriscv`
478 - `elf64-littleriscv`
484 - `elf32-ntradbigmips`
485 - `elf32-ntradlittlemips`
486 - `elf32-tradbigmips`
487 - `elf32-tradlittlemips`
488 - `elf64-tradbigmips`
489 - `elf64-tradlittlemips`
493 Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
496 BINARY INPUT AND OUTPUT
497 -----------------------
499 If `binary` is used as the value for :option:`--input-target`, the input file
500 will be embedded as a data section in an ELF relocatable object, with symbols
501 ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
502 ``_binary_<file_name>_size`` representing the start, end and size of the data,
503 where ``<file_name>`` is the path of the input file as specified on the command
504 line with non-alphanumeric characters converted to ``_``.
506 If `binary` is used as the value for :option:`--output-target`, the output file
507 will be a raw binary file, containing the memory image of the input file.
508 Symbols and relocation information will be discarded. The image will start at
509 the address of the first loadable section in the output.
514 :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
515 Otherwise, it exits with code 0.
520 To report bugs, please visit <http://llvm.org/bugs/>.
522 There is a known issue with :option:`--input-target` and :option:`--target`
523 causing only ``binary`` and ``ihex`` formats to have any effect. Other values
524 will be ignored and :program:`llvm-objcopy` will attempt to guess the input
530 :manpage:`llvm-strip(1)`