blob: 044293c7e8a6fe4607c709e1e84a5db2ddf5cf90 [file] [log] [blame]
James Hendersone26ca962019-07-03 14:21:48 +00001llvm-objcopy - object copying and editing tool
2==============================================
3
4.. program:: llvm-objcopy
5
6SYNOPSIS
7--------
8
9:program:`llvm-objcopy` [*options*] *input* [*output*]
10
11DESCRIPTION
12-----------
13
14:program:`llvm-objcopy` is a tool to copy and manipulate objects. In basic
15usage, it makes a semantic copy of the input to the output. If any options are
16specified, the output may be modified along the way, e.g. by removing sections.
17
18If no output file is specified, the input file is modified in-place. If "-" is
19specified for the input file, the input is read from the program's standard
20input stream. If "-" is specified for the output file, the output is written to
21the standard output stream of the program.
22
23If the input is an archive, any requested operations will be applied to each
24archive member individually.
25
26The tool is still in active development, but in most scenarios it works as a
27drop-in replacement for GNU's :program:`objcopy`.
28
29GENERIC AND CROSS-PLATFORM OPTIONS
30----------------------------------
31
32The following options are either agnostic of the file format, or apply to
33multiple file formats.
34
35.. option:: --add-gnu-debuglink <debug-file>
36
37 Add a .gnu_debuglink section for ``<debug-file>`` to the output.
38
Sergey Dmitrievcdeaac52019-07-26 17:06:41 +000039.. option:: --add-section <section=file>
40
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.
45
James Hendersone26ca962019-07-03 14:21:48 +000046.. option:: --disable-deterministic-archives, -U
47
48 Use real values for UIDs, GIDs and timestamps when updating archive member
49 headers.
50
51.. option:: --discard-all, -x
52
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.
56
57.. option:: --enable-deterministic-archives, -D
58
59 Enable deterministic mode when copying archives, i.e. use 0 for archive member
60 header UIDs, GIDs and timestamp fields. On by default.
61
62.. option:: --help, -h
63
64 Print a summary of command line options.
65
66.. option:: --only-section <section>, -j
67
68 Remove all sections from the output, except for sections named ``<section>``.
69 Can be specified multiple times to keep multiple sections.
70
71.. option:: --regex
72
73 If specified, symbol and section names specified by other switches are treated
74 as extended POSIX regular expression patterns.
75
76.. option:: --remove-section <section>, -R
77
78 Remove the specified section from the output. Can be specified multiple times
79 to remove multiple sections simultaneously.
80
81.. option:: --strip-all-gnu
82
83 Remove all symbols, debug sections and relocations from the output. This option
84 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
85
86.. option:: --strip-all, -S
87
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.
90
91 For COFF objects, remove all symbols, debug sections, and relocations from the
92 output.
93
94.. option:: --strip-debug, -g
95
96 Remove all debug sections from the output.
97
98.. option:: --strip-symbol <symbol>, -N
99
100 Remove all symbols named ``<symbol>`` from the output. Can be specified
101 multiple times to remove multiple symbols.
102
103.. option:: --strip-symbols <filename>
104
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.
109
110.. option:: --strip-unneeded-symbol <symbol>
111
112 Remove from the output all symbols named ``<symbol>`` that are local or
113 undefined and are not required by any relocation.
114
115.. option:: --strip-unneeded-symbols <filename>
116
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.
122
123.. option:: --strip-unneeded
124
125 Remove from the output all local or undefined symbols that are not required by
126 relocations.
127
128.. option:: --version, -V
129
130 Display the version of this program.
131
132COFF-SPECIFIC OPTIONS
133---------------------
134
135The following options are implemented only for COFF objects. If used with other
136objects, :program:`llvm-objcopy` will either emit an error or silently ignore
137them.
138
139.. option:: --only-keep-debug
140
141 Remove the contents of non-debug sections from the output, but keep the section
142 headers.
143
144ELF-SPECIFIC OPTIONS
145--------------------
146
147The following options are implemented only for ELF objects. If used with other
148objects, :program:`llvm-objcopy` will either emit an error or silently ignore
149them.
150
James Hendersone26ca962019-07-03 14:21:48 +0000151.. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
152
James Henderson1a517a42019-07-05 11:57:07 +0000153 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:
James Hendersone26ca962019-07-03 14:21:48 +0000157
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.
Chris Jacksone5cdfbc2019-08-15 09:45:09 +0000163 - `protected` = the symbol will have protected visibility.
James Hendersone26ca962019-07-03 14:21:48 +0000164 - `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.
169
170 Additionally, the following flags are accepted but ignored: `debug`,
171 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
172
173 Can be specified multiple times to add multiple symbols.
174
175.. option:: --allow-broken-links
176
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.
179
180.. option:: --binary-architecture <arch>, -B
181
182 Specify the architecture to use, when transforming an architecture-less format
183 (e.g. binary) to another format. Valid options are:
184
185 - `aarch64`
186 - `arm`
187 - `i386`
188 - `i386:x86-64`
189 - `mips`
190 - `powerpc:common64`
191 - `riscv:rv32`
192 - `riscv:rv64`
193 - `sparc`
194 - `sparcel`
195 - `x86-64`
196
197.. option:: --build-id-link-dir <dir>
198
199 Set the directory used by :option:`--build-id-link-input` and
200 :option:`--build-id-link-output`.
201
202.. option:: --build-id-link-input <suffix>
203
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
206 hex build ID.
207
208.. option:: --build-id-link-output <suffix>
209
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
212 hex build ID.
213
214.. option:: --change-start <incr>, --adjust-start
215
216 Add ``<incr>`` to the program's start address. Can be specified multiple
217 times, in which case the values will be applied cumulatively.
218
219.. option:: --compress-debug-sections [<style>]
220
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
223 specified.
224
225.. option:: --decompress-debug-sections
226
227 Decompress any compressed DWARF debug sections in the output.
228
229.. option:: --discard-locals, -X
230
231 Remove local symbols starting with ".L" from the output.
232
233.. option:: --dump-section <section>=<file>
234
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.
241
242.. option:: --extract-dwo
243
244 Remove all sections that are not DWARF .dwo sections from the output.
245
246.. option:: --extract-main-partition
247
248 Extract the main partition from the output.
249
250.. option:: --extract-partition <name>
251
252 Extract the named partition from the output.
253
254.. option:: --globalize-symbol <symbol>
255
256 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
257 Can be specified multiple times to mark multiple symbols.
258
259.. option:: --globalize-symbols <filename>
260
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.
265
266.. option:: --input-target <format>, -I
267
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.
271
272.. option:: --keep-file-symbols
273
274 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
275
276.. option:: --keep-global-symbol <symbol>
277
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.
280
281.. option:: --keep-global-symbols <filename>
282
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.
287
288.. option:: --keep-section <section>
289
290 When removing sections from the output, do not remove sections named
291 ``<section>``. Can be specified multiple times to keep multiple sections.
292
293.. option:: --keep-symbol <symbol>, -K
294
295 When removing symbols from the output, do not remove symbols named
296 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
297
298.. option:: --keep-symbols <filename>
299
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.
304
305.. option:: --localize-hidden
306
307 Make all symbols with hidden or internal visibility local in the output.
308
309.. option:: --localize-symbol <symbol>, -L
310
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.
313
314.. option:: --localize-symbols <filename>
315
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
320 multiple files.
321
322.. option:: --output-target <format>, -O
323
324 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
325 of valid ``<format>`` values. If unspecified, the output format is assumed to
326 be the same as the input file's format.
327
328.. option:: --prefix-alloc-sections <prefix>
329
330 Add ``<prefix>`` to the front of the names of all allocatable sections in the
331 output.
332
333.. option:: --prefix-symbols <prefix>
334
335 Add ``<prefix>`` to the front of every symbol name in the output.
336
337.. option:: --preserve-dates, -p
338
339 Preserve access and modification timestamps in the output.
340
341.. option:: --redefine-sym <old>=<new>
342
343 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
344 multiple times to rename multiple symbols.
345
346.. option:: --redefine-syms <filename>
347
348 Rename symbols in the output as described in the file ``<filename>``. In the
349 file, each line represents a single symbol to rename, with the old name and new
350 name separated by an equals sign. Leading and trailing whitespace is ignored,
351 as is anything following a '#'. Can be specified multiple times to read names
352 from multiple files.
353
354.. option:: --rename-section <old>=<new>[,<flag>,...]
355
356 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
357 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
358 supported flags. Can be specified multiple times to rename multiple sections.
359
360.. option:: --set-section-flags <section>=<flag>[,<flag>,...]
361
362 Set section properties in the output of section ``<section>`` based on the
363 specified ``<flag>`` values. Can be specified multiple times to update multiple
364 sections.
365
366 Following is a list of supported flags and their effects:
367
368 - `alloc` = add the `SHF_ALLOC` flag.
369 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
370 section.
371 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
372 - `code` = add the `SHF_EXECINSTR` flag.
373 - `merge` = add the `SHF_MERGE` flag.
374 - `strings` = add the `SHF_STRINGS` flag.
375 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
376 section.
377
378 The following flags are also accepted, but are ignored for GNU compatibility:
379 `noload`, `debug`, `data`, `rom`, `share`.
380
381.. option:: --set-start-addr <addr>
382
383 Set the start address of the output to ``<addr>``. Overrides any previously
384 specified :option:`--change-start` or :option:`--adjust-start` options.
385
386.. option:: --split-dwo <dwo-file>
387
388 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
389 ``<dwo-file>`` as the output file and no other options, and then with
390 :option:`--strip-dwo` on the input file.
391
392.. option:: --strip-dwo
393
394 Remove all DWARF .dwo sections from the output.
395
396.. option:: --strip-non-alloc
397
398 Remove from the output all non-allocatable sections that are not within
399 segments.
400
401.. option:: --strip-sections
402
403 Remove from the output all section headers and all section data not within
404 segments. Note that many tools will not be able to use an object without
405 section headers.
406
407.. option:: --target <format>, -F
408
409 Equivalent to :option:`--input-target` and :option:`--output-target` for the
410 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
411 values.
412
413.. option:: --weaken-symbol <symbol>, -W
414
415 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
416 be specified multiple times to mark multiple symbols as weak.
417
418.. option:: --weaken-symbols <filename>
419
420 Read a list of names from the file ``<filename>`` and mark global symbols with
421 those names as weak in the output. In the file, each line represents a single
422 symbol, with leading and trailing whitespace ignored, as is anything following
423 a '#'. Can be specified multiple times to read names from multiple files.
424
425.. option:: --weaken
426
427 Mark all defined global symbols as weak in the output.
428
429SUPPORTED FORMATS
430-----------------
431
432The following values are currently supported by :program:`llvm-objcopy` for the
433:option:`--input-target`, :option:`--output-target`, and :option:`--target`
434options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
435
436- `binary`
437- `ihex`
438- `elf32-i386`
439- `elf32-x86-64`
440- `elf64-x86-64`
441- `elf32-iamcu`
442- `elf32-littlearm`
443- `elf64-aarch64`
444- `elf64-littleaarch64`
445- `elf32-littleriscv`
446- `elf64-littleriscv`
447- `elf32-powerpc`
448- `elf32-powerpcle`
449- `elf64-powerpc`
450- `elf64-powerpcle`
451- `elf32-bigmips`
452- `elf32-ntradbigmips`
453- `elf32-ntradlittlemips`
454- `elf32-tradbigmips`
455- `elf32-tradlittlemips`
456- `elf64-tradbigmips`
457- `elf64-tradlittlemips`
458- `elf32-sparc`
459- `elf32-sparcel`
460
James Henderson8cf99a112019-07-08 11:41:54 +0000461Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
462suffix.
463
464BINARY INPUT AND OUTPUT
465-----------------------
466
467If `binary` is used as the value for :option:`--input-target`, the input file
468will be embedded as a data section in an ELF relocatable object, with symbols
469``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
470``_binary_<file_name>_size`` representing the start, end and size of the data,
471where ``<file_name>`` is the path of the input file as specified on the command
472line with non-alphanumeric characters converted to ``_``.
473
474If `binary` is used as the value for :option:`--output-target`, the output file
475will be a raw binary file, containing the memory image of the input file.
476Symbols and relocation information will be discarded. The image will start at
477the address of the first loadable section in the output.
James Hendersone26ca962019-07-03 14:21:48 +0000478
479EXIT STATUS
480-----------
481
482:program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
483Otherwise, it exits with code 0.
484
485BUGS
486----
487
488To report bugs, please visit <http://llvm.org/bugs/>.
489
490There is a known issue with :option:`--input-target` and :option:`--target`
491causing only ``binary`` and ``ihex`` formats to have any effect. Other values
492will be ignored and :program:`llvm-objcopy` will attempt to guess the input
493format.
494
495SEE ALSO
496--------
497
498:manpage:`llvm-strip(1)`