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:: --disable-deterministic-archives, -U
41 Use real values for UIDs, GIDs and timestamps when updating archive member
44 .. option:: --discard-all, -x
46 Remove most local symbols from the output. Different file formats may limit
47 this to a subset of the local symbols. For example, file and section symbols in
48 ELF objects will not be discarded.
50 .. option:: --enable-deterministic-archives, -D
52 Enable deterministic mode when copying archives, i.e. use 0 for archive member
53 header UIDs, GIDs and timestamp fields. On by default.
55 .. option:: --help, -h
57 Print a summary of command line options.
59 .. option:: --only-section <section>, -j
61 Remove all sections from the output, except for sections named ``<section>``.
62 Can be specified multiple times to keep multiple sections.
66 If specified, symbol and section names specified by other switches are treated
67 as extended POSIX regular expression patterns.
69 .. option:: --remove-section <section>, -R
71 Remove the specified section from the output. Can be specified multiple times
72 to remove multiple sections simultaneously.
74 .. option:: --strip-all-gnu
76 Remove all symbols, debug sections and relocations from the output. This option
77 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
79 .. option:: --strip-all, -S
81 For ELF objects, remove from the output all symbols and non-alloc sections not
82 within segments, except for .gnu.warning sections and the section name table.
84 For COFF objects, remove all symbols, debug sections, and relocations from the
87 .. option:: --strip-debug, -g
89 Remove all debug sections from the output.
91 .. option:: --strip-symbol <symbol>, -N
93 Remove all symbols named ``<symbol>`` from the output. Can be specified
94 multiple times to remove multiple symbols.
96 .. option:: --strip-symbols <filename>
98 Remove all symbols whose names appear in the file ``<filename>``, from the
99 output. In the file, each line represents a single symbol name, with leading
100 and trailing whitespace ignored, as is anything following a '#'. Can be
101 specified multiple times to read names from multiple files.
103 .. option:: --strip-unneeded-symbol <symbol>
105 Remove from the output all symbols named ``<symbol>`` that are local or
106 undefined and are not required by any relocation.
108 .. option:: --strip-unneeded-symbols <filename>
110 Remove all symbols whose names appear in the file ``<filename>``, from the
111 output, if they are local or undefined and are not required by any relocation.
112 In the file, each line represents a single symbol name, with leading and
113 trailing whitespace ignored, as is anything following a '#'. Can be specified
114 multiple times to read names from multiple files.
116 .. option:: --strip-unneeded
118 Remove from the output all local or undefined symbols that are not required by
121 .. option:: --version, -V
123 Display the version of this program.
125 COFF-SPECIFIC OPTIONS
126 ---------------------
128 The following options are implemented only for COFF objects. If used with other
129 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
132 .. option:: --only-keep-debug
134 Remove the contents of non-debug sections from the output, but keep the section
140 The following options are implemented only for ELF objects. If used with other
141 objects, :program:`llvm-objcopy` will either emit an error or silently ignore
144 .. option:: --add-section <section=file>
146 Add a section named ``<section>`` with the contents of ``<file>`` to the
147 output. The section will be of type `SHT_NOTE`, if the name starts with
148 ".note". Otherwise, it will have type `SHT_PROGBITS`. Can be specified multiple
149 times to add multiple sections.
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 - `file` = the symbol will be an `STT_FILE` symbol.
164 - `section` = the symbol will be an `STT_SECTION` symbol.
165 - `object` = the symbol will be an `STT_OBJECT` symbol.
166 - `function` = the symbol will be an `STT_FUNC` symbol.
167 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
169 Additionally, the following flags are accepted but ignored: `debug`,
170 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
172 Can be specified multiple times to add multiple symbols.
174 .. option:: --allow-broken-links
176 Allow llvm-objcopy to remove sections even if it would leave invalid section
177 references. Any invalid sh_link fields will be set to zero.
179 .. option:: --binary-architecture <arch>, -B
181 Specify the architecture to use, when transforming an architecture-less format
182 (e.g. binary) to another format. Valid options are:
196 .. option:: --build-id-link-dir <dir>
198 Set the directory used by :option:`--build-id-link-input` and
199 :option:`--build-id-link-output`.
201 .. option:: --build-id-link-input <suffix>
203 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
204 specified by :option:`--build-id-link-dir`. The path used is derived from the
207 .. option:: --build-id-link-output <suffix>
209 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
210 specified by :option:`--build-id-link-dir`. The path used is derived from the
213 .. option:: --change-start <incr>, --adjust-start
215 Add ``<incr>`` to the program's start address. Can be specified multiple
216 times, in which case the values will be applied cumulatively.
218 .. option:: --compress-debug-sections [<style>]
220 Compress DWARF debug sections in the output, using the specified style.
221 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
224 .. option:: --decompress-debug-sections
226 Decompress any compressed DWARF debug sections in the output.
228 .. option:: --discard-locals, -X
230 Remove local symbols starting with ".L" from the output.
232 .. option:: --dump-section <section>=<file>
234 Dump the contents of section ``<section>`` into the file ``<file>``. Can be
235 specified multiple times to dump multiple sections to different files.
236 ``<file>`` is unrelated to the input and output files provided to
237 :program:`llvm-objcopy` and as such the normal copying and editing
238 operations will still be performed. No operations are performed on the sections
239 prior to dumping them.
241 .. option:: --extract-dwo
243 Remove all sections that are not DWARF .dwo sections from the output.
245 .. option:: --extract-main-partition
247 Extract the main partition from the output.
249 .. option:: --extract-partition <name>
251 Extract the named partition from the output.
253 .. option:: --globalize-symbol <symbol>
255 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
256 Can be specified multiple times to mark multiple symbols.
258 .. option:: --globalize-symbols <filename>
260 Read a list of names from the file ``<filename>`` and mark defined symbols with
261 those names as global in the output. In the file, each line represents a single
262 symbol, with leading and trailing whitespace ignored, as is anything following
263 a '#'. Can be specified multiple times to read names from multiple files.
265 .. option:: --input-target <format>, -I
267 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
268 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
269 to determine the format automatically.
271 .. option:: --keep-file-symbols
273 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
275 .. option:: --keep-global-symbol <symbol>
277 Make all symbols local in the output, except for symbols with the name
278 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
280 .. option:: --keep-global-symbols <filename>
282 Make all symbols local in the output, except for symbols named in the file
283 ``<filename>``. In the file, each line represents a single symbol, with leading
284 and trailing whitespace ignored, as is anything following a '#'. Can be
285 specified multiple times to read names from multiple files.
287 .. option:: --keep-section <section>
289 When removing sections from the output, do not remove sections named
290 ``<section>``. Can be specified multiple times to keep multiple sections.
292 .. option:: --keep-symbol <symbol>, -K
294 When removing symbols from the output, do not remove symbols named
295 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
297 .. option:: --keep-symbols <filename>
299 When removing symbols from the output do not remove symbols named in the file
300 ``<filename>``. In the file, each line represents a single symbol, with leading
301 and trailing whitespace ignored, as is anything following a '#'. Can be
302 specified multiple times to read names from multiple files.
304 .. option:: --localize-hidden
306 Make all symbols with hidden or internal visibility local in the output.
308 .. option:: --localize-symbol <symbol>, -L
310 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
311 output. Can be specified multiple times to mark multiple symbols as local.
313 .. option:: --localize-symbols <filename>
315 Read a list of names from the file ``<filename>`` and mark defined non-common
316 symbols with those names as local in the output. In the file, each line
317 represents a single symbol, with leading and trailing whitespace ignored, as is
318 anything following a '#'. Can be specified multiple times to read names from
321 .. option:: --output-target <format>, -O
323 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
324 of valid ``<format>`` values. If unspecified, the output format is assumed to
325 be the same as the input file's format.
327 .. option:: --prefix-alloc-sections <prefix>
329 Add ``<prefix>`` to the front of the names of all allocatable sections in the
332 .. option:: --prefix-symbols <prefix>
334 Add ``<prefix>`` to the front of every symbol name in the output.
336 .. option:: --preserve-dates, -p
338 Preserve access and modification timestamps in the output.
340 .. option:: --redefine-sym <old>=<new>
342 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
343 multiple times to rename multiple symbols.
345 .. option:: --redefine-syms <filename>
347 Rename symbols in the output as described in the file ``<filename>``. In the
348 file, each line represents a single symbol to rename, with the old name and new
349 name separated by an equals sign. Leading and trailing whitespace is ignored,
350 as is anything following a '#'. Can be specified multiple times to read names
353 .. option:: --rename-section <old>=<new>[,<flag>,...]
355 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
356 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
357 supported flags. Can be specified multiple times to rename multiple sections.
359 .. option:: --set-section-flags <section>=<flag>[,<flag>,...]
361 Set section properties in the output of section ``<section>`` based on the
362 specified ``<flag>`` values. Can be specified multiple times to update multiple
365 Following is a list of supported flags and their effects:
367 - `alloc` = add the `SHF_ALLOC` flag.
368 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
370 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
371 - `code` = add the `SHF_EXECINSTR` flag.
372 - `merge` = add the `SHF_MERGE` flag.
373 - `strings` = add the `SHF_STRINGS` flag.
374 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
377 The following flags are also accepted, but are ignored for GNU compatibility:
378 `noload`, `debug`, `data`, `rom`, `share`.
380 .. option:: --set-start-addr <addr>
382 Set the start address of the output to ``<addr>``. Overrides any previously
383 specified :option:`--change-start` or :option:`--adjust-start` options.
385 .. option:: --split-dwo <dwo-file>
387 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
388 ``<dwo-file>`` as the output file and no other options, and then with
389 :option:`--strip-dwo` on the input file.
391 .. option:: --strip-dwo
393 Remove all DWARF .dwo sections from the output.
395 .. option:: --strip-non-alloc
397 Remove from the output all non-allocatable sections that are not within
400 .. option:: --strip-sections
402 Remove from the output all section headers and all section data not within
403 segments. Note that many tools will not be able to use an object without
406 .. option:: --target <format>, -F
408 Equivalent to :option:`--input-target` and :option:`--output-target` for the
409 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
412 .. option:: --weaken-symbol <symbol>, -W
414 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
415 be specified multiple times to mark multiple symbols as weak.
417 .. option:: --weaken-symbols <filename>
419 Read a list of names from the file ``<filename>`` and mark global symbols with
420 those names as weak in the output. In the file, each line represents a single
421 symbol, with leading and trailing whitespace ignored, as is anything following
422 a '#'. Can be specified multiple times to read names from multiple files.
426 Mark all defined global symbols as weak in the output.
431 The following values are currently supported by :program:`llvm-objcopy` for the
432 :option:`--input-target`, :option:`--output-target`, and :option:`--target`
433 options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
443 - `elf64-littleaarch64`
444 - `elf32-littleriscv`
445 - `elf64-littleriscv`
451 - `elf32-ntradbigmips`
452 - `elf32-ntradlittlemips`
453 - `elf32-tradbigmips`
454 - `elf32-tradlittlemips`
455 - `elf64-tradbigmips`
456 - `elf64-tradlittlemips`
460 Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
463 BINARY INPUT AND OUTPUT
464 -----------------------
466 If `binary` is used as the value for :option:`--input-target`, the input file
467 will be embedded as a data section in an ELF relocatable object, with symbols
468 ``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
469 ``_binary_<file_name>_size`` representing the start, end and size of the data,
470 where ``<file_name>`` is the path of the input file as specified on the command
471 line with non-alphanumeric characters converted to ``_``.
473 If `binary` is used as the value for :option:`--output-target`, the output file
474 will be a raw binary file, containing the memory image of the input file.
475 Symbols and relocation information will be discarded. The image will start at
476 the address of the first loadable section in the output.
481 :program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
482 Otherwise, it exits with code 0.
487 To report bugs, please visit <http://llvm.org/bugs/>.
489 There is a known issue with :option:`--input-target` and :option:`--target`
490 causing only ``binary`` and ``ihex`` formats to have any effect. Other values
491 will be ignored and :program:`llvm-objcopy` will attempt to guess the input
497 :manpage:`llvm-strip(1)`