xref: /netbsd-src/external/apache2/llvm/dist/llvm/docs/CommandGuide/llvm-objcopy.rst (revision ed75d7a867996c84cfa88e3b8906816277e957f7)
1llvm-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
39.. 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
46.. option:: --binary-architecture <arch>, -B
47
48 Ignored for compatibility.
49
50.. 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 For MachO objects, ``<section>`` must be formatted as
76 ``<segment name>,<section name>``.
77
78.. option:: --regex
79
80 If specified, symbol and section names specified by other switches are treated
81 as extended POSIX regular expression patterns.
82
83.. option:: --remove-section <section>, -R
84
85 Remove the specified section from the output. Can be specified multiple times
86 to remove multiple sections simultaneously.
87
88.. option:: --set-section-alignment <section>=<align>
89
90 Set the alignment of section ``<section>`` to `<align>``. Can be specified
91 multiple times to update multiple sections.
92
93.. option:: --strip-all-gnu
94
95 Remove all symbols, debug sections and relocations from the output. This option
96 is equivalent to GNU :program:`objcopy`'s ``--strip-all`` switch.
97
98.. option:: --strip-all, -S
99
100 For ELF objects, remove from the output all symbols and non-alloc sections not
101 within segments, except for .gnu.warning sections and the section name table.
102
103 For COFF objects, remove all symbols, debug sections, and relocations from the
104 output.
105
106.. option:: --strip-debug, -g
107
108 Remove all debug sections from the output.
109
110.. option:: --strip-symbol <symbol>, -N
111
112 Remove all symbols named ``<symbol>`` from the output. Can be specified
113 multiple times to remove multiple symbols.
114
115.. option:: --strip-symbols <filename>
116
117 Remove all symbols whose names appear in the file ``<filename>``, from the
118 output. In the file, each line represents a single symbol name, with leading
119 and trailing whitespace ignored, as is anything following a '#'. Can be
120 specified multiple times to read names from multiple files.
121
122.. option:: --strip-unneeded-symbol <symbol>
123
124 Remove from the output all symbols named ``<symbol>`` that are local or
125 undefined and are not required by any relocation.
126
127.. option:: --strip-unneeded-symbols <filename>
128
129 Remove all symbols whose names appear in the file ``<filename>``, from the
130 output, if they are local or undefined and are not required by any relocation.
131 In the file, each line represents a single symbol name, with leading and
132 trailing whitespace ignored, as is anything following a '#'. Can be specified
133 multiple times to read names from multiple files.
134
135.. option:: --strip-unneeded
136
137 Remove from the output all local or undefined symbols that are not required by
138 relocations. Also remove all debug sections.
139
140.. option:: --version, -V
141
142 Display the version of the :program:`llvm-objcopy` executable.
143
144.. option:: @<FILE>
145
146 Read command-line options and commands from response file `<FILE>`.
147
148.. option:: --wildcard, -w
149
150  Allow wildcard syntax for symbol-related flags. On by default for
151  section-related flags. Incompatible with --regex.
152
153  Wildcard syntax allows the following special symbols:
154
155  ====================== ========================= ==================
156   Character              Meaning                   Equivalent
157  ====================== ========================= ==================
158  ``*``                  Any number of characters  ``.*``
159  ``?``                  Any single character      ``.``
160  ``\``                  Escape the next character ``\``
161  ``[a-z]``              Character class           ``[a-z]``
162  ``[!a-z]``, ``[^a-z]`` Negated character class   ``[^a-z]``
163  ====================== ========================= ==================
164
165  Additionally, starting a wildcard with '!' will prevent a match, even if
166  another flag matches. For example ``-w -N '*' -N '!x'`` will strip all symbols
167  except for ``x``.
168
169  The order of wildcards does not matter. For example, ``-w -N '*' -N '!x'`` is
170  the same as ``-w -N '!x' -N '*'``.
171
172COFF-SPECIFIC OPTIONS
173---------------------
174
175The following options are implemented only for COFF objects. If used with other
176objects, :program:`llvm-objcopy` will either emit an error or silently ignore
177them.
178
179.. option:: --only-keep-debug
180
181 Remove the contents of non-debug sections from the output, but keep the section
182 headers.
183
184ELF-SPECIFIC OPTIONS
185--------------------
186
187The following options are implemented only for ELF objects. If used with other
188objects, :program:`llvm-objcopy` will either emit an error or silently ignore
189them.
190
191.. option:: --add-symbol <name>=[<section>:]<value>[,<flags>]
192
193 Add a new symbol called ``<name>`` to the output symbol table, in the section
194 named ``<section>``, with value ``<value>``. If ``<section>`` is not specified,
195 the symbol is added as an absolute symbol. The ``<flags>`` affect the symbol
196 properties. Accepted values are:
197
198 - `global` = the symbol will have global binding.
199 - `local` = the symbol will have local binding.
200 - `weak` = the symbol will have weak binding.
201 - `default` = the symbol will have default visibility.
202 - `hidden` = the symbol will have hidden visibility.
203 - `protected` = the symbol will have protected visibility.
204 - `file` = the symbol will be an `STT_FILE` symbol.
205 - `section` = the symbol will be an `STT_SECTION` symbol.
206 - `object` = the symbol will be an `STT_OBJECT` symbol.
207 - `function` = the symbol will be an `STT_FUNC` symbol.
208 - `indirect-function` = the symbol will be an `STT_GNU_IFUNC` symbol.
209
210 Additionally, the following flags are accepted but ignored: `debug`,
211 `constructor`, `warning`, `indirect`, `synthetic`, `unique-object`, `before`.
212
213 Can be specified multiple times to add multiple symbols.
214
215.. option:: --allow-broken-links
216
217 Allow :program:`llvm-objcopy` to remove sections even if it would leave invalid
218 section references. Any invalid sh_link fields will be set to zero.
219
220.. option:: --build-id-link-dir <dir>
221
222 Set the directory used by :option:`--build-id-link-input` and
223 :option:`--build-id-link-output`.
224
225.. option:: --build-id-link-input <suffix>
226
227 Hard-link the input to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
228 specified by :option:`--build-id-link-dir`. The path used is derived from the
229 hex build ID.
230
231.. option:: --build-id-link-output <suffix>
232
233 Hard-link the output to ``<dir>/xx/xxx<suffix>``, where ``<dir>`` is the directory
234 specified by :option:`--build-id-link-dir`. The path used is derived from the
235 hex build ID.
236
237.. option:: --change-start <incr>, --adjust-start
238
239 Add ``<incr>`` to the program's start address. Can be specified multiple
240 times, in which case the values will be applied cumulatively.
241
242.. option:: --compress-debug-sections [<style>]
243
244 Compress DWARF debug sections in the output, using the specified style.
245 Supported styles are `zlib-gnu` and `zlib`. Defaults to `zlib` if no style is
246 specified.
247
248.. option:: --decompress-debug-sections
249
250 Decompress any compressed DWARF debug sections in the output.
251
252.. option:: --discard-locals, -X
253
254 Remove local symbols starting with ".L" from the output.
255
256.. option:: --dump-section <section>=<file>
257
258 Dump the contents of section ``<section>`` into the file ``<file>``. Can be
259 specified multiple times to dump multiple sections to different files.
260 ``<file>`` is unrelated to the input and output files provided to
261 :program:`llvm-objcopy` and as such the normal copying and editing
262 operations will still be performed. No operations are performed on the sections
263 prior to dumping them.
264
265.. option:: --extract-dwo
266
267 Remove all sections that are not DWARF .dwo sections from the output.
268
269.. option:: --extract-main-partition
270
271 Extract the main partition from the output.
272
273.. option:: --extract-partition <name>
274
275 Extract the named partition from the output.
276
277.. option:: --globalize-symbol <symbol>
278
279 Mark any defined symbols named ``<symbol>`` as global symbols in the output.
280 Can be specified multiple times to mark multiple symbols.
281
282.. option:: --globalize-symbols <filename>
283
284 Read a list of names from the file ``<filename>`` and mark defined symbols with
285 those names as global in the output. In the file, each line represents a single
286 symbol, with leading and trailing whitespace ignored, as is anything following
287 a '#'. Can be specified multiple times to read names from multiple files.
288
289.. option:: --input-target <format>, -I
290
291 Read the input as the specified format. See `SUPPORTED FORMATS`_ for a list of
292 valid ``<format>`` values. If unspecified, :program:`llvm-objcopy` will attempt
293 to determine the format automatically.
294
295.. option:: --keep-file-symbols
296
297 Keep symbols of type `STT_FILE`, even if they would otherwise be stripped.
298
299.. option:: --keep-global-symbol <symbol>
300
301 Make all symbols local in the output, except for symbols with the name
302 ``<symbol>``. Can be specified multiple times to ignore multiple symbols.
303
304.. option:: --keep-global-symbols <filename>
305
306 Make all symbols local in the output, except for symbols named in the file
307 ``<filename>``. In the file, each line represents a single symbol, with leading
308 and trailing whitespace ignored, as is anything following a '#'. Can be
309 specified multiple times to read names from multiple files.
310
311.. option:: --keep-section <section>
312
313 When removing sections from the output, do not remove sections named
314 ``<section>``. Can be specified multiple times to keep multiple sections.
315
316.. option:: --keep-symbol <symbol>, -K
317
318 When removing symbols from the output, do not remove symbols named
319 ``<symbol>``. Can be specified multiple times to keep multiple symbols.
320
321.. option:: --keep-symbols <filename>
322
323 When removing symbols from the output do not remove symbols named in the file
324 ``<filename>``. In the file, each line represents a single symbol, with leading
325 and trailing whitespace ignored, as is anything following a '#'. Can be
326 specified multiple times to read names from multiple files.
327
328.. option:: --localize-hidden
329
330 Make all symbols with hidden or internal visibility local in the output.
331
332.. option:: --localize-symbol <symbol>, -L
333
334 Mark any defined non-common symbol named ``<symbol>`` as a local symbol in the
335 output. Can be specified multiple times to mark multiple symbols as local.
336
337.. option:: --localize-symbols <filename>
338
339 Read a list of names from the file ``<filename>`` and mark defined non-common
340 symbols with those names as local in the output. In the file, each line
341 represents a single symbol, with leading and trailing whitespace ignored, as is
342 anything following a '#'. Can be specified multiple times to read names from
343 multiple files.
344
345.. option:: --new-symbol-visibility <visibility>
346
347 Specify the visibility of the symbols automatically created when using binary
348 input or :option:`--add-symbol`. Valid options are:
349
350 - `default`
351 - `hidden`
352 - `internal`
353 - `protected`
354
355 The default is `default`.
356
357.. option:: --output-target <format>, -O
358
359 Write the output as the specified format. See `SUPPORTED FORMATS`_ for a list
360 of valid ``<format>`` values. If unspecified, the output format is assumed to
361 be the same as the input file's format.
362
363.. option:: --prefix-alloc-sections <prefix>
364
365 Add ``<prefix>`` to the front of the names of all allocatable sections in the
366 output.
367
368.. option:: --prefix-symbols <prefix>
369
370 Add ``<prefix>`` to the front of every symbol name in the output.
371
372.. option:: --preserve-dates, -p
373
374 Preserve access and modification timestamps in the output.
375
376.. option:: --redefine-sym <old>=<new>
377
378 Rename symbols called ``<old>`` to ``<new>`` in the output. Can be specified
379 multiple times to rename multiple symbols.
380
381.. option:: --redefine-syms <filename>
382
383 Rename symbols in the output as described in the file ``<filename>``. In the
384 file, each line represents a single symbol to rename, with the old name and new
385 name separated by an equals sign. Leading and trailing whitespace is ignored,
386 as is anything following a '#'. Can be specified multiple times to read names
387 from multiple files.
388
389.. option:: --rename-section <old>=<new>[,<flag>,...]
390
391 Rename sections called ``<old>`` to ``<new>`` in the output, and apply any
392 specified ``<flag>`` values. See :option:`--set-section-flags` for a list of
393 supported flags. Can be specified multiple times to rename multiple sections.
394
395.. option:: --set-section-flags <section>=<flag>[,<flag>,...]
396
397 Set section properties in the output of section ``<section>`` based on the
398 specified ``<flag>`` values. Can be specified multiple times to update multiple
399 sections.
400
401 Following is a list of supported flags and their effects:
402
403 - `alloc` = add the `SHF_ALLOC` flag.
404 - `load` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
405   section.
406 - `readonly` = if this flag is not specified, add the `SHF_WRITE` flag.
407 - `code` = add the `SHF_EXECINSTR` flag.
408 - `merge` = add the `SHF_MERGE` flag.
409 - `strings` = add the `SHF_STRINGS` flag.
410 - `contents` = if the section has `SHT_NOBITS` type, mark it as a `SHT_PROGBITS`
411   section.
412
413 The following flags are also accepted, but are ignored for GNU compatibility:
414 `noload`, `debug`, `data`, `rom`, `share`.
415
416.. option:: --set-start-addr <addr>
417
418 Set the start address of the output to ``<addr>``. Overrides any previously
419 specified :option:`--change-start` or :option:`--adjust-start` options.
420
421.. option:: --split-dwo <dwo-file>
422
423 Equivalent to running :program:`llvm-objcopy` with :option:`--extract-dwo` and
424 ``<dwo-file>`` as the output file and no other options, and then with
425 :option:`--strip-dwo` on the input file.
426
427.. option:: --strip-dwo
428
429 Remove all DWARF .dwo sections from the output.
430
431.. option:: --strip-non-alloc
432
433 Remove from the output all non-allocatable sections that are not within
434 segments.
435
436.. option:: --strip-sections
437
438 Remove from the output all section headers and all section data not within
439 segments. Note that many tools will not be able to use an object without
440 section headers.
441
442.. option:: --target <format>, -F
443
444 Equivalent to :option:`--input-target` and :option:`--output-target` for the
445 specified format. See `SUPPORTED FORMATS`_ for a list of valid ``<format>``
446 values.
447
448.. option:: --weaken-symbol <symbol>, -W
449
450 Mark any global symbol named ``<symbol>`` as a weak symbol in the output. Can
451 be specified multiple times to mark multiple symbols as weak.
452
453.. option:: --weaken-symbols <filename>
454
455 Read a list of names from the file ``<filename>`` and mark global symbols with
456 those names as weak in the output. In the file, each line represents a single
457 symbol, with leading and trailing whitespace ignored, as is anything following
458 a '#'. Can be specified multiple times to read names from multiple files.
459
460.. option:: --weaken
461
462 Mark all defined global symbols as weak in the output.
463
464SUPPORTED FORMATS
465-----------------
466
467The following values are currently supported by :program:`llvm-objcopy` for the
468:option:`--input-target`, :option:`--output-target`, and :option:`--target`
469options. For GNU :program:`objcopy` compatibility, the values are all bfdnames.
470
471- `binary`
472- `ihex`
473- `elf32-i386`
474- `elf32-x86-64`
475- `elf64-x86-64`
476- `elf32-iamcu`
477- `elf32-littlearm`
478- `elf64-aarch64`
479- `elf64-littleaarch64`
480- `elf32-littleriscv`
481- `elf64-littleriscv`
482- `elf32-powerpc`
483- `elf32-powerpcle`
484- `elf64-powerpc`
485- `elf64-powerpcle`
486- `elf32-bigmips`
487- `elf32-ntradbigmips`
488- `elf32-ntradlittlemips`
489- `elf32-tradbigmips`
490- `elf32-tradlittlemips`
491- `elf64-tradbigmips`
492- `elf64-tradlittlemips`
493- `elf32-sparc`
494- `elf32-sparcel`
495
496Additionally, all targets except `binary` and `ihex` can have `-freebsd` as a
497suffix.
498
499BINARY INPUT AND OUTPUT
500-----------------------
501
502If `binary` is used as the value for :option:`--input-target`, the input file
503will be embedded as a data section in an ELF relocatable object, with symbols
504``_binary_<file_name>_start``, ``_binary_<file_name>_end``, and
505``_binary_<file_name>_size`` representing the start, end and size of the data,
506where ``<file_name>`` is the path of the input file as specified on the command
507line with non-alphanumeric characters converted to ``_``.
508
509If `binary` is used as the value for :option:`--output-target`, the output file
510will be a raw binary file, containing the memory image of the input file.
511Symbols and relocation information will be discarded. The image will start at
512the address of the first loadable section in the output.
513
514EXIT STATUS
515-----------
516
517:program:`llvm-objcopy` exits with a non-zero exit code if there is an error.
518Otherwise, it exits with code 0.
519
520BUGS
521----
522
523To report bugs, please visit <http://llvm.org/bugs/>.
524
525There is a known issue with :option:`--input-target` and :option:`--target`
526causing only ``binary`` and ``ihex`` formats to have any effect. Other values
527will be ignored and :program:`llvm-objcopy` will attempt to guess the input
528format.
529
530SEE ALSO
531--------
532
533:manpage:`llvm-strip(1)`
534