2 .\" Man page generated from reStructuredText.
5 .nr rst2man-indent-level 0
9 level \\n[rst2man-indent-level]
10 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
17 .\" .rstReportMargin pre:
19 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
20 . nr rst2man-indent-level +1
21 .\" .rstReportMargin post:
25 .\" indent \\n[an-margin]
26 .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
27 .nr rst2man-indent-level -1
28 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
29 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
31 .TH "LLVM-OBJCOPY" "1" "2021-06-07" "12" "LLVM"
33 llvm-objcopy \- object copying and editing tool
36 \fBllvm\-objcopy\fP [\fIoptions\fP] \fIinput\fP [\fIoutput\fP]
39 \fBllvm\-objcopy\fP is a tool to copy and manipulate objects. In basic
40 usage, it makes a semantic copy of the input to the output. If any options are
41 specified, the output may be modified along the way, e.g. by removing sections.
43 If no output file is specified, the input file is modified in\-place. If "\-" is
44 specified for the input file, the input is read from the program\(aqs standard
45 input stream. If "\-" is specified for the output file, the output is written to
46 the standard output stream of the program.
48 If the input is an archive, any requested operations will be applied to each
49 archive member individually.
51 The tool is still in active development, but in most scenarios it works as a
52 drop\-in replacement for GNU\(aqs \fBobjcopy\fP\&.
53 .SH GENERIC AND CROSS-PLATFORM OPTIONS
55 The following options are either agnostic of the file format, or apply to
56 multiple file formats.
59 .B \-\-add\-gnu\-debuglink <debug\-file>
60 Add a .gnu_debuglink section for \fB<debug\-file>\fP to the output.
64 .B \-\-add\-section <section=file>
65 Add a section named \fB<section>\fP with the contents of \fB<file>\fP to the
66 output. For ELF objects the section will be of type \fISHT_NOTE\fP, if the name
67 starts with ".note". Otherwise, it will have type \fISHT_PROGBITS\fP\&. Can be
68 specified multiple times to add multiple sections.
70 For MachO objects, \fB<section>\fP must be formatted as
71 \fB<segment name>,<section name>\fP\&.
75 .B \-\-binary\-architecture <arch>, \-B
76 Ignored for compatibility.
80 .B \-\-disable\-deterministic\-archives, \-U
81 Use real values for UIDs, GIDs and timestamps when updating archive member
86 .B \-\-discard\-all, \-x
87 Remove most local symbols from the output. Different file formats may limit
88 this to a subset of the local symbols. For example, file and section symbols in
89 ELF objects will not be discarded.
93 .B \-\-dump\-section <section>=<file>
94 Dump the contents of section \fB<section>\fP into the file \fB<file>\fP\&. Can be
95 specified multiple times to dump multiple sections to different files.
96 \fB<file>\fP is unrelated to the input and output files provided to
97 \fBllvm\-objcopy\fP and as such the normal copying and editing
98 operations will still be performed. No operations are performed on the sections
99 prior to dumping them.
101 For MachO objects, \fB<section>\fP must be formatted as
102 \fB<segment name>,<section name>\fP\&.
106 .B \-\-enable\-deterministic\-archives, \-D
107 Enable deterministic mode when copying archives, i.e. use 0 for archive member
108 header UIDs, GIDs and timestamp fields. On by default.
113 Print a summary of command line options.
117 .B \-\-only\-keep\-debug
118 Produce a debug file as the output that only preserves contents of sections
119 useful for debugging purposes.
121 For ELF objects, this removes the contents of \fISHF_ALLOC\fP sections that are not
122 \fISHT_NOTE\fP by making them \fISHT_NOBITS\fP and shrinking the program headers where
127 .B \-\-only\-section <section>, \-j
128 Remove all sections from the output, except for sections named \fB<section>\fP\&.
129 Can be specified multiple times to keep multiple sections.
131 For MachO objects, \fB<section>\fP must be formatted as
132 \fB<segment name>,<section name>\fP\&.
136 .B \-\-redefine\-sym <old>=<new>
137 Rename symbols called \fB<old>\fP to \fB<new>\fP in the output. Can be specified
138 multiple times to rename multiple symbols.
142 .B \-\-redefine\-syms <filename>
143 Rename symbols in the output as described in the file \fB<filename>\fP\&. In the
144 file, each line represents a single symbol to rename, with the old name and new
145 name separated by whitespace. Leading and trailing whitespace is ignored, as is
146 anything following a \(aq#\(aq. Can be specified multiple times to read names from
152 If specified, symbol and section names specified by other switches are treated
153 as extended POSIX regular expression patterns.
157 .B \-\-remove\-section <section>, \-R
158 Remove the specified section from the output. Can be specified multiple times
159 to remove multiple sections simultaneously.
161 For MachO objects, \fB<section>\fP must be formatted as
162 \fB<segment name>,<section name>\fP\&.
166 .B \-\-set\-section\-alignment <section>=<align>
167 Set the alignment of section \fB<section>\fP to \fI<align>\(ga\fP\&. Can be specified
168 multiple times to update multiple sections.
172 .B \-\-set\-section\-flags <section>=<flag>[,<flag>,...]
173 Set section properties in the output of section \fB<section>\fP based on the
174 specified \fB<flag>\fP values. Can be specified multiple times to update multiple
177 Supported flag names are \fIalloc\fP, \fIload\fP, \fInoload\fP, \fIreadonly\fP, \fIexclude\fP,
178 \fIdebug\fP, \fIcode\fP, \fIdata\fP, \fIrom\fP, \fIshare\fP, \fIcontents\fP, \fImerge\fP and \fIstrings\fP\&. Not
179 all flags are meaningful for all object file formats.
181 For ELF objects, the flags have the following effects:
184 \fIalloc\fP = add the \fISHF_ALLOC\fP flag.
186 \fIload\fP = if the section has \fISHT_NOBITS\fP type, mark it as a \fISHT_PROGBITS\fP
189 \fIreadonly\fP = if this flag is not specified, add the \fISHF_WRITE\fP flag.
191 \fIexclude\fP = add the \fISHF_EXCLUDE\fP flag.
193 \fIcode\fP = add the \fISHF_EXECINSTR\fP flag.
195 \fImerge\fP = add the \fISHF_MERGE\fP flag.
197 \fIstrings\fP = add the \fISHF_STRINGS\fP flag.
199 \fIcontents\fP = if the section has \fISHT_NOBITS\fP type, mark it as a \fISHT_PROGBITS\fP
203 For COFF objects, the flags have the following effects:
206 \fIalloc\fP = add the \fIIMAGE_SCN_CNT_UNINITIALIZED_DATA\fP and \fIIMAGE_SCN_MEM_READ\fP
207 flags, unless the \fIload\fP flag is specified.
209 \fInoload\fP = add the \fIIMAGE_SCN_LNK_REMOVE\fP and \fIIMAGE_SCN_MEM_READ\fP flags.
211 \fIreadonly\fP = if this flag is not specified, add the \fIIMAGE_SCN_MEM_WRITE\fP
214 \fIexclude\fP = add the \fIIMAGE_SCN_LNK_REMOVE\fP and \fIIMAGE_SCN_MEM_READ\fP flags.
216 \fIdebug\fP = add the \fIIMAGE_SCN_CNT_INITIALIZED_DATA\fP,
217 \fIIMAGE_SCN_MEM_DISCARDABLE\fP and \fIIMAGE_SCN_MEM_READ\fP flags.
219 \fIcode\fP = add the \fIIMAGE_SCN_CNT_CODE\fP, \fIIMAGE_SCN_MEM_EXECUTE\fP and
220 \fIIMAGE_SCN_MEM_READ\fP flags.
222 \fIdata\fP = add the \fIIMAGE_SCN_CNT_INITIALIZED_DATA\fP and \fIIMAGE_SCN_MEM_READ\fP
225 \fIshare\fP = add the \fIIMAGE_SCN_MEM_SHARED\fP and \fIIMAGE_SCN_MEM_READ\fP flags.
230 .B \-\-strip\-all\-gnu
231 Remove all symbols, debug sections and relocations from the output. This option
232 is equivalent to GNU \fBobjcopy\fP\(aqs \fB\-\-strip\-all\fP switch.
236 .B \-\-strip\-all, \-S
237 For ELF objects, remove from the output all symbols and non\-alloc sections not
238 within segments, except for .gnu.warning, .ARM.attribute sections and the
241 For COFF and Mach\-O objects, remove all symbols, debug sections, and
242 relocations from the output.
246 .B \-\-strip\-debug, \-g
247 Remove all debug sections from the output.
251 .B \-\-strip\-symbol <symbol>, \-N
252 Remove all symbols named \fB<symbol>\fP from the output. Can be specified
253 multiple times to remove multiple symbols.
257 .B \-\-strip\-symbols <filename>
258 Remove all symbols whose names appear in the file \fB<filename>\fP, from the
259 output. In the file, each line represents a single symbol name, with leading
260 and trailing whitespace ignored, as is anything following a \(aq#\(aq. Can be
261 specified multiple times to read names from multiple files.
265 .B \-\-strip\-unneeded\-symbol <symbol>
266 Remove from the output all symbols named \fB<symbol>\fP that are local or
267 undefined and are not required by any relocation.
271 .B \-\-strip\-unneeded\-symbols <filename>
272 Remove all symbols whose names appear in the file \fB<filename>\fP, from the
273 output, if they are local or undefined and are not required by any relocation.
274 In the file, each line represents a single symbol name, with leading and
275 trailing whitespace ignored, as is anything following a \(aq#\(aq. Can be specified
276 multiple times to read names from multiple files.
280 .B \-\-strip\-unneeded
281 Remove from the output all local or undefined symbols that are not required by
282 relocations. Also remove all debug sections.
287 Display the version of the \fBllvm\-objcopy\fP executable.
292 Allow wildcard syntax for symbol\-related flags. On by default for
293 section\-related flags. Incompatible with \-\-regex.
295 Wildcard syntax allows the following special symbols:
311 Any number of characters
327 Escape the next character
341 \fB[!a\-z]\fP, \fB[^a\-z]\fP
343 Negated character class
350 Additionally, starting a wildcard with \(aq!\(aq will prevent a match, even if
351 another flag matches. For example \fB\-w \-N \(aq*\(aq \-N \(aq!x\(aq\fP will strip all symbols
352 except for \fBx\fP\&.
354 The order of wildcards does not matter. For example, \fB\-w \-N \(aq*\(aq \-N \(aq!x\(aq\fP is
355 the same as \fB\-w \-N \(aq!x\(aq \-N \(aq*\(aq\fP\&.
360 Read command\-line options and commands from response file \fI<FILE>\fP\&.
362 .SH ELF-SPECIFIC OPTIONS
364 The following options are implemented only for ELF objects. If used with other
365 objects, \fBllvm\-objcopy\fP will either emit an error or silently ignore
369 .B \-\-add\-symbol <name>=[<section>:]<value>[,<flags>]
370 Add a new symbol called \fB<name>\fP to the output symbol table, in the section
371 named \fB<section>\fP, with value \fB<value>\fP\&. If \fB<section>\fP is not specified,
372 the symbol is added as an absolute symbol. The \fB<flags>\fP affect the symbol
373 properties. Accepted values are:
376 \fIglobal\fP = the symbol will have global binding.
378 \fIlocal\fP = the symbol will have local binding.
380 \fIweak\fP = the symbol will have weak binding.
382 \fIdefault\fP = the symbol will have default visibility.
384 \fIhidden\fP = the symbol will have hidden visibility.
386 \fIprotected\fP = the symbol will have protected visibility.
388 \fIfile\fP = the symbol will be an \fISTT_FILE\fP symbol.
390 \fIsection\fP = the symbol will be an \fISTT_SECTION\fP symbol.
392 \fIobject\fP = the symbol will be an \fISTT_OBJECT\fP symbol.
394 \fIfunction\fP = the symbol will be an \fISTT_FUNC\fP symbol.
396 \fIindirect\-function\fP = the symbol will be an \fISTT_GNU_IFUNC\fP symbol.
399 Additionally, the following flags are accepted but ignored: \fIdebug\fP,
400 \fIconstructor\fP, \fIwarning\fP, \fIindirect\fP, \fIsynthetic\fP, \fIunique\-object\fP, \fIbefore\fP\&.
402 Can be specified multiple times to add multiple symbols.
406 .B \-\-allow\-broken\-links
407 Allow \fBllvm\-objcopy\fP to remove sections even if it would leave invalid
408 section references. Any invalid sh_link fields will be set to zero.
412 .B \-\-build\-id\-link\-dir <dir>
413 Set the directory used by \fI\%\-\-build\-id\-link\-input\fP and
414 \fI\%\-\-build\-id\-link\-output\fP\&.
418 .B \-\-build\-id\-link\-input <suffix>
419 Hard\-link the input to \fB<dir>/xx/xxx<suffix>\fP, where \fB<dir>\fP is the directory
420 specified by \fI\%\-\-build\-id\-link\-dir\fP\&. The path used is derived from the
425 .B \-\-build\-id\-link\-output <suffix>
426 Hard\-link the output to \fB<dir>/xx/xxx<suffix>\fP, where \fB<dir>\fP is the directory
427 specified by \fI\%\-\-build\-id\-link\-dir\fP\&. The path used is derived from the
432 .B \-\-change\-start <incr>, \-\-adjust\-start
433 Add \fB<incr>\fP to the program\(aqs start address. Can be specified multiple
434 times, in which case the values will be applied cumulatively.
438 .B \-\-compress\-debug\-sections [<style>]
439 Compress DWARF debug sections in the output, using the specified style.
440 Supported styles are \fIzlib\-gnu\fP and \fIzlib\fP\&. Defaults to \fIzlib\fP if no style is
445 .B \-\-decompress\-debug\-sections
446 Decompress any compressed DWARF debug sections in the output.
450 .B \-\-discard\-locals, \-X
451 Remove local symbols starting with ".L" from the output.
456 Remove all sections that are not DWARF .dwo sections from the output.
460 .B \-\-extract\-main\-partition
461 Extract the main partition from the output.
465 .B \-\-extract\-partition <name>
466 Extract the named partition from the output.
470 .B \-\-globalize\-symbol <symbol>
471 Mark any defined symbols named \fB<symbol>\fP as global symbols in the output.
472 Can be specified multiple times to mark multiple symbols.
476 .B \-\-globalize\-symbols <filename>
477 Read a list of names from the file \fB<filename>\fP and mark defined symbols with
478 those names as global in the output. In the file, each line represents a single
479 symbol, with leading and trailing whitespace ignored, as is anything following
480 a \(aq#\(aq. Can be specified multiple times to read names from multiple files.
484 .B \-\-input\-target <format>, \-I
485 Read the input as the specified format. See \fI\%SUPPORTED FORMATS\fP for a list of
486 valid \fB<format>\fP values. If unspecified, \fBllvm\-objcopy\fP will attempt
487 to determine the format automatically.
491 .B \-\-keep\-file\-symbols
492 Keep symbols of type \fISTT_FILE\fP, even if they would otherwise be stripped.
496 .B \-\-keep\-global\-symbol <symbol>
497 Make all symbols local in the output, except for symbols with the name
498 \fB<symbol>\fP\&. Can be specified multiple times to ignore multiple symbols.
502 .B \-\-keep\-global\-symbols <filename>
503 Make all symbols local in the output, except for symbols named in the file
504 \fB<filename>\fP\&. In the file, each line represents a single symbol, with leading
505 and trailing whitespace ignored, as is anything following a \(aq#\(aq. Can be
506 specified multiple times to read names from multiple files.
510 .B \-\-keep\-section <section>
511 When removing sections from the output, do not remove sections named
512 \fB<section>\fP\&. Can be specified multiple times to keep multiple sections.
516 .B \-\-keep\-symbol <symbol>, \-K
517 When removing symbols from the output, do not remove symbols named
518 \fB<symbol>\fP\&. Can be specified multiple times to keep multiple symbols.
522 .B \-\-keep\-symbols <filename>
523 When removing symbols from the output do not remove symbols named in the file
524 \fB<filename>\fP\&. In the file, each line represents a single symbol, with leading
525 and trailing whitespace ignored, as is anything following a \(aq#\(aq. Can be
526 specified multiple times to read names from multiple files.
530 .B \-\-localize\-hidden
531 Make all symbols with hidden or internal visibility local in the output.
535 .B \-\-localize\-symbol <symbol>, \-L
536 Mark any defined non\-common symbol named \fB<symbol>\fP as a local symbol in the
537 output. Can be specified multiple times to mark multiple symbols as local.
541 .B \-\-localize\-symbols <filename>
542 Read a list of names from the file \fB<filename>\fP and mark defined non\-common
543 symbols with those names as local in the output. In the file, each line
544 represents a single symbol, with leading and trailing whitespace ignored, as is
545 anything following a \(aq#\(aq. Can be specified multiple times to read names from
550 .B \-\-new\-symbol\-visibility <visibility>
551 Specify the visibility of the symbols automatically created when using binary
552 input or \fI\%\-\-add\-symbol\fP\&. Valid options are:
564 The default is \fIdefault\fP\&.
568 .B \-\-output\-target <format>, \-O
569 Write the output as the specified format. See \fI\%SUPPORTED FORMATS\fP for a list
570 of valid \fB<format>\fP values. If unspecified, the output format is assumed to
571 be the same as the value specified for \fI\%\-\-input\-target\fP or the input
572 file\(aqs format if that option is also unspecified.
576 .B \-\-prefix\-alloc\-sections <prefix>
577 Add \fB<prefix>\fP to the front of the names of all allocatable sections in the
582 .B \-\-prefix\-symbols <prefix>
583 Add \fB<prefix>\fP to the front of every symbol name in the output.
587 .B \-\-preserve\-dates, \-p
588 Preserve access and modification timestamps in the output.
592 .B \-\-rename\-section <old>=<new>[,<flag>,...]
593 Rename sections called \fB<old>\fP to \fB<new>\fP in the output, and apply any
594 specified \fB<flag>\fP values. See \fI\%\-\-set\-section\-flags\fP for a list of
595 supported flags. Can be specified multiple times to rename multiple sections.
599 .B \-\-set\-start\-addr <addr>
600 Set the start address of the output to \fB<addr>\fP\&. Overrides any previously
601 specified \fI\%\-\-change\-start\fP or \fI\%\-\-adjust\-start\fP options.
605 .B \-\-split\-dwo <dwo\-file>
606 Equivalent to running \fBllvm\-objcopy\fP with \fI\%\-\-extract\-dwo\fP and
607 \fB<dwo\-file>\fP as the output file and no other options, and then with
608 \fI\%\-\-strip\-dwo\fP on the input file.
613 Remove all DWARF .dwo sections from the output.
617 .B \-\-strip\-non\-alloc
618 Remove from the output all non\-allocatable sections that are not within
623 .B \-\-strip\-sections
624 Remove from the output all section headers and all section data not within
625 segments. Note that many tools will not be able to use an object without
630 .B \-\-target <format>, \-F
631 Equivalent to \fI\%\-\-input\-target\fP and \fI\%\-\-output\-target\fP for the
632 specified format. See \fI\%SUPPORTED FORMATS\fP for a list of valid \fB<format>\fP
637 .B \-\-weaken\-symbol <symbol>, \-W
638 Mark any global symbol named \fB<symbol>\fP as a weak symbol in the output. Can
639 be specified multiple times to mark multiple symbols as weak.
643 .B \-\-weaken\-symbols <filename>
644 Read a list of names from the file \fB<filename>\fP and mark global symbols with
645 those names as weak in the output. In the file, each line represents a single
646 symbol, with leading and trailing whitespace ignored, as is anything following
647 a \(aq#\(aq. Can be specified multiple times to read names from multiple files.
652 Mark all defined global symbols as weak in the output.
654 .SH SUPPORTED FORMATS
656 The following values are currently supported by \fBllvm\-objcopy\fP for the
657 \fI\%\-\-input\-target\fP, \fI\%\-\-output\-target\fP, and \fI\%\-\-target\fP
658 options. For GNU \fBobjcopy\fP compatibility, the values are all bfdnames.
673 \fIelf32\-littlearm\fP
677 \fIelf64\-littleaarch64\fP
679 \fIelf32\-littleriscv\fP
681 \fIelf64\-littleriscv\fP
685 \fIelf32\-powerpcle\fP
689 \fIelf64\-powerpcle\fP
693 \fIelf32\-ntradbigmips\fP
695 \fIelf32\-ntradlittlemips\fP
697 \fIelf32\-tradbigmips\fP
699 \fIelf32\-tradlittlemips\fP
701 \fIelf64\-tradbigmips\fP
703 \fIelf64\-tradlittlemips\fP
710 Additionally, all targets except \fIbinary\fP and \fIihex\fP can have \fI\-freebsd\fP as a
712 .SH BINARY INPUT AND OUTPUT
714 If \fIbinary\fP is used as the value for \fI\%\-\-input\-target\fP, the input file
715 will be embedded as a data section in an ELF relocatable object, with symbols
716 \fB_binary_<file_name>_start\fP, \fB_binary_<file_name>_end\fP, and
717 \fB_binary_<file_name>_size\fP representing the start, end and size of the data,
718 where \fB<file_name>\fP is the path of the input file as specified on the command
719 line with non\-alphanumeric characters converted to \fB_\fP\&.
721 If \fIbinary\fP is used as the value for \fI\%\-\-output\-target\fP, the output file
722 will be a raw binary file, containing the memory image of the input file.
723 Symbols and relocation information will be discarded. The image will start at
724 the address of the first loadable section in the output.
727 \fBllvm\-objcopy\fP exits with a non\-zero exit code if there is an error.
728 Otherwise, it exits with code 0.
731 To report bugs, please visit <\fI\%https://bugs.llvm.org/\fP>.
733 There is a known issue with \fI\%\-\-input\-target\fP and \fI\%\-\-target\fP
734 causing only \fBbinary\fP and \fBihex\fP formats to have any effect. Other values
735 will be ignored and \fBllvm\-objcopy\fP will attempt to guess the input
741 Maintained by the LLVM Team (https://llvm.org/).
743 2003-2021, LLVM Project
744 .\" Generated by docutils manpage writer.