blob: 56c3a77716b6d56c38ea93da254bcfe21c3fd8a3 [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
Fangrui Song2f519d72019-09-14 01:36:31 +000046.. option:: --binary-architecture <arch>, -B
47
48 Ignored for compatibility.
49
James Hendersone26ca962019-07-03 14:21:48 +000050.. option:: --disable-deterministic-archives, -U
51
52 Use real values for UIDs, GIDs and timestamps when updating archive member
53 headers.
54
55.. option:: --discard-all, -x
56
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.
60
61.. option:: --enable-deterministic-archives, -D
62
63 Enable deterministic mode when copying archives, i.e. use 0 for archive member
64 header UIDs, GIDs and timestamp fields. On by default.
65
66.. option:: --help, -h
67
68 Print a summary of command line options.
69
70.. option:: --only-section <section>, -j
71
72 Remove all sections from the output, except for sections named ``<section>``.
73 Can be specified multiple times to keep multiple sections.
74
75.. option:: --regex
76
77 If specified, symbol and section names specified by other switches are treated
78 as extended POSIX regular expression patterns.
79
80.. option:: --remove-section <section>, -R
81
82 Remove the specified section from the output. Can be specified multiple times
83 to remove multiple sections simultaneously.
84
Fangrui Song671fb342019-10-02 12:41:25 +000085.. option:: --set-section-alignment <section>=<align>
86
87 Set the alignment of section ``<section>`` to `<align>``. Can be specified
88 multiple times to update multiple sections.
89
James Hendersone26ca962019-07-03 14:21:48 +000090.. option:: --strip-all-gnu
91
92 Remove all symbols, debug sections and relocations from the output. This option
93 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
94
95.. option:: --strip-all, -S
96
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.
99
100 For COFF objects, remove all symbols, debug sections, and relocations from the
101 output.
102
103.. option:: --strip-debug, -g
104
105 Remove all debug sections from the output.
106
107.. option:: --strip-symbol <symbol>, -N
108
109 Remove all symbols named ``<symbol>`` from the output. Can be specified
110 multiple times to remove multiple symbols.
111
112.. option:: --strip-symbols <filename>
113
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.
118
119.. option:: --strip-unneeded-symbol <symbol>
120
121 Remove from the output all symbols named ``<symbol>`` that are local or
122 undefined and are not required by any relocation.
123
124.. option:: --strip-unneeded-symbols <filename>
125
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.
131
132.. option:: --strip-unneeded
133
134 Remove from the output all local or undefined symbols that are not required by
James Henderson818e5c92019-09-13 13:26:52 +0000135 relocations. Also remove all debug sections.
James Hendersone26ca962019-07-03 14:21:48 +0000136
137.. option:: --version, -V
138
James Henderson778a5e52019-09-17 11:43:42 +0000139 Display the version of the :program:`llvm-objcopy` executable.
James Hendersone26ca962019-07-03 14:21:48 +0000140
Michael Pozulpc45fd0c2019-09-14 01:14:43 +0000141.. option:: @<FILE>
142
James Henderson778a5e52019-09-17 11:43:42 +0000143 Read command-line options and commands from response file `<FILE>`.
Michael Pozulpc45fd0c2019-09-14 01:14:43 +0000144
Jordan Rupprechtedeebad2019-10-17 20:51:00 +0000145.. option:: --wildcard, -w
146
147 Allow wildcard syntax for symbol-related flags. On by default for
148 section-related flags. Incompatible with --regex.
149
150 Wildcard syntax allows the following special symbols:
151
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 ====================== ========================= ==================
161
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
164 except for ``x``.
165
166 The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is
167 the same as ``-w -N '!x' -N '*'``.
168
James Hendersone26ca962019-07-03 14:21:48 +0000169COFF-SPECIFIC OPTIONS
170---------------------
171
172The following options are implemented only for COFF objects. If used with other
173objects, :program:`llvm-objcopy` will either emit an error or silently ignore
174them.
175
176.. option:: --only-keep-debug
177
178 Remove the contents of non-debug sections from the output, but keep the section
179 headers.
180
181ELF-SPECIFIC OPTIONS
182--------------------
183
184The following options are implemented only for ELF objects. If used with other
185objects, :program:`llvm-objcopy` will either emit an error or silently ignore
186them.
187
James Hendersone26ca962019-07-03 14:21:48 +0000188.. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
189
James Henderson1a517a42019-07-05 11:57:07 +0000190 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:
James Hendersone26ca962019-07-03 14:21:48 +0000194
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.
Chris Jacksone5cdfbc2019-08-15 09:45:09 +0000200 - `protected` = the symbol will have protected visibility.
James Hendersone26ca962019-07-03 14:21:48 +0000201 - `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.
206
207 Additionally, the following flags are accepted but ignored: `debug`,
208 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
209
210 Can be specified multiple times to add multiple symbols.
211
212.. option:: --allow-broken-links
213
James Henderson1b103862019-09-24 13:41:39 +0000214 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.
James Hendersone26ca962019-07-03 14:21:48 +0000216
James Hendersone26ca962019-07-03 14:21:48 +0000217.. option:: --build-id-link-dir <dir>
218
219 Set the directory used by :option:`--build-id-link-input` and
220 :option:`--build-id-link-output`.
221
222.. option:: --build-id-link-input <suffix>
223
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
226 hex build ID.
227
228.. option:: --build-id-link-output <suffix>
229
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
232 hex build ID.
233
234.. option:: --change-start <incr>, --adjust-start
235
236 Add ``<incr>`` to the program's start address. Can be specified multiple
237 times, in which case the values will be applied cumulatively.
238
239.. option:: --compress-debug-sections [<style>]
240
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
243 specified.
244
245.. option:: --decompress-debug-sections
246
247 Decompress any compressed DWARF debug sections in the output.
248
249.. option:: --discard-locals, -X
250
251 Remove local symbols starting with ".L" from the output.
252
253.. option:: --dump-section <section>=<file>
254
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.
261
262.. option:: --extract-dwo
263
264 Remove all sections that are not DWARF .dwo sections from the output.
265
266.. option:: --extract-main-partition
267
268 Extract the main partition from the output.
269
270.. option:: --extract-partition <name>
271
272 Extract the named partition from the output.
273
274.. option:: --globalize-symbol <symbol>
275
276 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
277 Can be specified multiple times to mark multiple symbols.
278
279.. option:: --globalize-symbols <filename>
280
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.
285
286.. option:: --input-target <format>, -I
287
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.
291
292.. option:: --keep-file-symbols
293
294 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
295
296.. option:: --keep-global-symbol <symbol>
297
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.
300
301.. option:: --keep-global-symbols <filename>
302
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.
307
308.. option:: --keep-section <section>
309
310 When removing sections from the output, do not remove sections named
311 ``<section>``. Can be specified multiple times to keep multiple sections.
312
313.. option:: --keep-symbol <symbol>, -K
314
315 When removing symbols from the output, do not remove symbols named
316 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
317
318.. option:: --keep-symbols <filename>
319
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.
324
325.. option:: --localize-hidden
326
327 Make all symbols with hidden or internal visibility local in the output.
328
329.. option:: --localize-symbol <symbol>, -L
330
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.
333
334.. option:: --localize-symbols <filename>
335
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
340 multiple files.
Chris Jacksonfa1fe932019-08-30 10:17:16 +0000341
342.. option:: --new-symbol-visibility <visibility>
343
344 Specify the visibility of the symbols automatically created when using binary
345 input or :option:`--add-symbol`. Valid options are:
346
347 - `default`
348 - `hidden`
349 - `internal`
350 - `protected`
351
352 The default is `default`.
James Hendersone26ca962019-07-03 14:21:48 +0000353
354.. option:: --output-target <format>, -O
355
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.
359
360.. option:: --prefix-alloc-sections <prefix>
361
362 Add ``<prefix>`` to the front of the names of all allocatable sections in the
363 output.
364
365.. option:: --prefix-symbols <prefix>
366
367 Add ``<prefix>`` to the front of every symbol name in the output.
368
369.. option:: --preserve-dates, -p
370
371 Preserve access and modification timestamps in the output.
372
373.. option:: --redefine-sym <old>=<new>
374
375 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
376 multiple times to rename multiple symbols.
377
378.. option:: --redefine-syms <filename>
379
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
384 from multiple files.
385
386.. option:: --rename-section <old>=<new>[,<flag>,...]
387
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.
391
392.. option:: --set-section-flags <section>=<flag>[,<flag>,...]
393
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
396 sections.
397
398 Following is a list of supported flags and their effects:
399
400 - `alloc` = add the `SHF_ALLOC` flag.
401 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
402 section.
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`
408 section.
409
410 The following flags are also accepted, but are ignored for GNU compatibility:
411 `noload`, `debug`, `data`, `rom`, `share`.
412
413.. option:: --set-start-addr <addr>
414
415 Set the start address of the output to ``<addr>``. Overrides any previously
416 specified :option:`--change-start` or :option:`--adjust-start` options.
417
418.. option:: --split-dwo <dwo-file>
419
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.
423
424.. option:: --strip-dwo
425
426 Remove all DWARF .dwo sections from the output.
427
428.. option:: --strip-non-alloc
429
430 Remove from the output all non-allocatable sections that are not within
431 segments.
432
433.. option:: --strip-sections
434
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
437 section headers.
438
439.. option:: --target <format>, -F
440
441 Equivalent to :option:`--input-target` and :option:`--output-target` for the
442 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
443 values.
444
445.. option:: --weaken-symbol <symbol>, -W
446
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.
449
450.. option:: --weaken-symbols <filename>
451
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.
456
457.. option:: --weaken
458
459 Mark all defined global symbols as weak in the output.
460
461SUPPORTED FORMATS
462-----------------
463
464The following values are currently supported by :program:`llvm-objcopy` for the
465:option:`--input-target`, :option:`--output-target`, and :option:`--target`
466options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
467
468- `binary`
469- `ihex`
470- `elf32-i386`
471- `elf32-x86-64`
472- `elf64-x86-64`
473- `elf32-iamcu`
474- `elf32-littlearm`
475- `elf64-aarch64`
476- `elf64-littleaarch64`
477- `elf32-littleriscv`
478- `elf64-littleriscv`
479- `elf32-powerpc`
480- `elf32-powerpcle`
481- `elf64-powerpc`
482- `elf64-powerpcle`
483- `elf32-bigmips`
484- `elf32-ntradbigmips`
485- `elf32-ntradlittlemips`
486- `elf32-tradbigmips`
487- `elf32-tradlittlemips`
488- `elf64-tradbigmips`
489- `elf64-tradlittlemips`
490- `elf32-sparc`
491- `elf32-sparcel`
492
James Henderson8cf99a112019-07-08 11:41:54 +0000493Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
494suffix.
495
496BINARY INPUT AND OUTPUT
497-----------------------
498
499If `binary` is used as the value for :option:`--input-target`, the input file
500will 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,
503where ``<file_name>`` is the path of the input file as specified on the command
504line with non-alphanumeric characters converted to ``_``.
505
506If `binary` is used as the value for :option:`--output-target`, the output file
507will be a raw binary file, containing the memory image of the input file.
508Symbols and relocation information will be discarded. The image will start at
509the address of the first loadable section in the output.
James Hendersone26ca962019-07-03 14:21:48 +0000510
511EXIT STATUS
512-----------
513
514:program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
515Otherwise, it exits with code 0.
516
517BUGS
518----
519
520To report bugs, please visit <http://llvm.org/bugs/>.
521
522There is a known issue with :option:`--input-target` and :option:`--target`
523causing only ``binary`` and ``ihex`` formats to have any effect. Other values
524will be ignored and :program:`llvm-objcopy` will attempt to guess the input
525format.
526
527SEE ALSO
528--------
529
530:manpage:`llvm-strip(1)`