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:: --strip-all-gnu
87 Remove all symbols, debug sections and relocations from the output. This option
88 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
90 .. option:: --strip-all, -S
92 For ELF objects, remove from the output all symbols and non-alloc sections not
93 within segments, except for .gnu.warning sections and the section name table.
95 For COFF objects, remove all symbols, debug sections, and relocations from the
98 .. option:: --strip-debug, -g
100 Remove all debug sections from the output.
102 .. option:: --strip-symbol <symbol>, -N
104 Remove all symbols named ``<symbol>`` from the output. Can be specified
105 multiple times to remove multiple symbols.
107 .. option:: --strip-symbols <filename>
109 Remove all symbols whose names appear in the file ``<filename>``, from the
110 output. In the file, each line represents a single symbol name, with leading
111 and trailing whitespace ignored, as is anything following a '#'. Can be
112 specified multiple times to read names from multiple files.
114 .. option:: --strip-unneeded-symbol <symbol>
116 Remove from the output all symbols named ``<symbol>`` that are local or
117 undefined and are not required by any relocation.
119 .. option:: --strip-unneeded-symbols <filename>
121 Remove all symbols whose names appear in the file ``<filename>``, from the
122 output, if they are local or undefined and are not required by any relocation.
123 In the file, each line represents a single symbol name, with leading and
124 trailing whitespace ignored, as is anything following a '#'. Can be specified
125 multiple times to read names from multiple files.
127 .. option:: --strip-unneeded
129 Remove from the output all local or undefined symbols that are not required by
130 relocations. Also remove all debug sections.
132 .. option:: --version, -V
134 Display the version of the :program:`llvm-objcopy` executable.
138 Read command-line options and commands from response file `<FILE>`.
140 COFF-SPECIFIC OPTIONS
141 ---------------------
143 The following options are implemented only for COFF objects. If used with other
144 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
147 .. option:: --only-keep-debug
149 Remove the contents of non-debug sections from the output, but keep the section
155 The following options are implemented only for ELF objects. If used with other
156 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
159 .. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
161 Add a new symbol called ``<name>`` to the output symbol table, in the section
162 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
163 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
164 properties. Accepted values are:
166 - `global` = the symbol will have global binding.
167 - `local` = the symbol will have local binding.
168 - `weak` = the symbol will have weak binding.
169 - `default` = the symbol will have default visibility.
170 - `hidden` = the symbol will have hidden visibility.
171 - `protected` = the symbol will have protected visibility.
172 - `file` = the symbol will be an `STT_FILE` symbol.
173 - `section` = the symbol will be an `STT_SECTION` symbol.
174 - `object` = the symbol will be an `STT_OBJECT` symbol.
175 - `function` = the symbol will be an `STT_FUNC` symbol.
176 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
178 Additionally, the following flags are accepted but ignored: `debug`,
179 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
181 Can be specified multiple times to add multiple symbols.
183 .. option:: --allow-broken-links
185 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
186 section references. Any invalid sh_link fields will be set to zero.
188 .. option:: --build-id-link-dir <dir>
190 Set the directory used by :option:`--build-id-link-input` and
191 :option:`--build-id-link-output`.
193 .. option:: --build-id-link-input <suffix>
195 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
196 specified by :option:`--build-id-link-dir`. The path used is derived from the
199 .. option:: --build-id-link-output <suffix>
201 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
202 specified by :option:`--build-id-link-dir`. The path used is derived from the
205 .. option:: --change-start <incr>, --adjust-start
207 Add ``<incr>`` to the program's start address. Can be specified multiple
208 times, in which case the values will be applied cumulatively.
210 .. option:: --compress-debug-sections [<style>]
212 Compress DWARF debug sections in the output, using the specified style.
213 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
216 .. option:: --decompress-debug-sections
218 Decompress any compressed DWARF debug sections in the output.
220 .. option:: --discard-locals, -X
222 Remove local symbols starting with ".L" from the output.
224 .. option:: --dump-section <section>=<file>
226 Dump the contents of section ``<section>`` into the file ``<file>``. Can be
227 specified multiple times to dump multiple sections to different files.
228 ``<file>`` is unrelated to the input and output files provided to
229 :program:`llvm-objcopy` and as such the normal copying and editing
230 operations will still be performed. No operations are performed on the sections
231 prior to dumping them.
233 .. option:: --extract-dwo
235 Remove all sections that are not DWARF .dwo sections from the output.
237 .. option:: --extract-main-partition
239 Extract the main partition from the output.
241 .. option:: --extract-partition <name>
243 Extract the named partition from the output.
245 .. option:: --globalize-symbol <symbol>
247 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
248 Can be specified multiple times to mark multiple symbols.
250 .. option:: --globalize-symbols <filename>
252 Read a list of names from the file ``<filename>`` and mark defined symbols with
253 those names as global in the output. In the file, each line represents a single
254 symbol, with leading and trailing whitespace ignored, as is anything following
255 a '#'. Can be specified multiple times to read names from multiple files.
257 .. option:: --input-target <format>, -I
259 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
260 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
261 to determine the format automatically.
263 .. option:: --keep-file-symbols
265 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
267 .. option:: --keep-global-symbol <symbol>
269 Make all symbols local in the output, except for symbols with the name
270 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
272 .. option:: --keep-global-symbols <filename>
274 Make all symbols local in the output, except for symbols named in the file
275 ``<filename>``. In the file, each line represents a single symbol, with leading
276 and trailing whitespace ignored, as is anything following a '#'. Can be
277 specified multiple times to read names from multiple files.
279 .. option:: --keep-section <section>
281 When removing sections from the output, do not remove sections named
282 ``<section>``. Can be specified multiple times to keep multiple sections.
284 .. option:: --keep-symbol <symbol>, -K
286 When removing symbols from the output, do not remove symbols named
287 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
289 .. option:: --keep-symbols <filename>
291 When removing symbols from the output do not remove symbols named in the file
292 ``<filename>``. In the file, each line represents a single symbol, with leading
293 and trailing whitespace ignored, as is anything following a '#'. Can be
294 specified multiple times to read names from multiple files.
296 .. option:: --localize-hidden
298 Make all symbols with hidden or internal visibility local in the output.
300 .. option:: --localize-symbol <symbol>, -L
302 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
303 output. Can be specified multiple times to mark multiple symbols as local.
305 .. option:: --localize-symbols <filename>
307 Read a list of names from the file ``<filename>`` and mark defined non-common
308 symbols with those names as local in the output. In the file, each line
309 represents a single symbol, with leading and trailing whitespace ignored, as is
310 anything following a '#'. Can be specified multiple times to read names from
313 .. option:: --new-symbol-visibility <visibility>
315 Specify the visibility of the symbols automatically created when using binary
316 input or :option:`--add-symbol`. Valid options are:
323 The default is `default`.
325 .. option:: --output-target <format>, -O
327 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
328 of valid ``<format>`` values. If unspecified, the output format is assumed to
329 be the same as the input file's format.
331 .. option:: --prefix-alloc-sections <prefix>
333 Add ``<prefix>`` to the front of the names of all allocatable sections in the
336 .. option:: --prefix-symbols <prefix>
338 Add ``<prefix>`` to the front of every symbol name in the output.
340 .. option:: --preserve-dates, -p
342 Preserve access and modification timestamps in the output.
344 .. option:: --redefine-sym <old>=<new>
346 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
347 multiple times to rename multiple symbols.
349 .. option:: --redefine-syms <filename>
351 Rename symbols in the output as described in the file ``<filename>``. In the
352 file, each line represents a single symbol to rename, with the old name and new
353 name separated by an equals sign. Leading and trailing whitespace is ignored,
354 as is anything following a '#'. Can be specified multiple times to read names
357 .. option:: --rename-section <old>=<new>[,<flag>,...]
359 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
360 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
361 supported flags. Can be specified multiple times to rename multiple sections.
363 .. option:: --set-section-flags <section>=<flag>[,<flag>,...]
365 Set section properties in the output of section ``<section>`` based on the
366 specified ``<flag>`` values. Can be specified multiple times to update multiple
369 Following is a list of supported flags and their effects:
371 - `alloc` = add the `SHF_ALLOC` flag.
372 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
374 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
375 - `code` = add the `SHF_EXECINSTR` flag.
376 - `merge` = add the `SHF_MERGE` flag.
377 - `strings` = add the `SHF_STRINGS` flag.
378 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
381 The following flags are also accepted, but are ignored for GNU compatibility:
382 `noload`, `debug`, `data`, `rom`, `share`.
384 .. option:: --set-start-addr <addr>
386 Set the start address of the output to ``<addr>``. Overrides any previously
387 specified :option:`--change-start` or :option:`--adjust-start` options.
389 .. option:: --split-dwo <dwo-file>
391 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
392 ``<dwo-file>`` as the output file and no other options, and then with
393 :option:`--strip-dwo` on the input file.
395 .. option:: --strip-dwo
397 Remove all DWARF .dwo sections from the output.
399 .. option:: --strip-non-alloc
401 Remove from the output all non-allocatable sections that are not within
404 .. option:: --strip-sections
406 Remove from the output all section headers and all section data not within
407 segments. Note that many tools will not be able to use an object without
410 .. option:: --target <format>, -F
412 Equivalent to :option:`--input-target` and :option:`--output-target` for the
413 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
416 .. option:: --weaken-symbol <symbol>, -W
418 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
419 be specified multiple times to mark multiple symbols as weak.
421 .. option:: --weaken-symbols <filename>
423 Read a list of names from the file ``<filename>`` and mark global symbols with
424 those names as weak in the output. In the file, each line represents a single
425 symbol, with leading and trailing whitespace ignored, as is anything following
426 a '#'. Can be specified multiple times to read names from multiple files.
430 Mark all defined global symbols as weak in the output.
435 The following values are currently supported by :program:`llvm-objcopy` for the
436 :option:`--input-target`, :option:`--output-target`, and :option:`--target`
437 options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
447 - `elf64-littleaarch64`
448 - `elf32-littleriscv`
449 - `elf64-littleriscv`
455 - `elf32-ntradbigmips`
456 - `elf32-ntradlittlemips`
457 - `elf32-tradbigmips`
458 - `elf32-tradlittlemips`
459 - `elf64-tradbigmips`
460 - `elf64-tradlittlemips`
464 Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
467 BINARY INPUT AND OUTPUT
468 -----------------------
470 If `binary` is used as the value for :option:`--input-target`, the input file
471 will be embedded as a data section in an ELF relocatable object, with symbols
472 ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
473 ``_binary_<file_name>_size`` representing the start, end and size of the data,
474 where ``<file_name>`` is the path of the input file as specified on the command
475 line with non-alphanumeric characters converted to ``_``.
477 If `binary` is used as the value for :option:`--output-target`, the output file
478 will be a raw binary file, containing the memory image of the input file.
479 Symbols and relocation information will be discarded. The image will start at
480 the address of the first loadable section in the output.
485 :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
486 Otherwise, it exits with code 0.
491 To report bugs, please visit <http://llvm.org/bugs/>.
493 There is a known issue with :option:`--input-target` and :option:`--target`
494 causing only ``binary`` and ``ihex`` formats to have any effect. Other values
495 will be ignored and :program:`llvm-objcopy` will attempt to guess the input
501 :manpage:`llvm-strip(1)`