llvm-objcopy - object copying and editing tool¶
:::{program} llvm-objcopy :::
SYNOPSIS¶
llvm-objcopy [options] input [output]
DESCRIPTION¶
llvm-objcopy is a tool to copy and manipulate objects. In basic usage, it makes a semantic copy of the input to the output. If any options are specified, the output may be modified along the way, e.g. by removing sections.
If no output file is specified, the input file is modified in-place. If “-” is specified for the input file, the input is read from the program’s standard input stream. If “-” is specified for the output file, the output is written to the standard output stream of the program.
If the input is an archive, any requested operations will be applied to each archive member individually.
The tool is still in active development, but in most scenarios it works as a drop-in replacement for GNU’s objcopy.
GENERIC AND CROSS-PLATFORM OPTIONS¶
The following options are either agnostic of the file format, or apply to multiple file formats.
:::{option} –add-gnu-debuglink <debug-file> to the output.
:::
:::{option} –add-section <section=file>
Add a section named <section> with the contents of <file> to the
output. For ELF objects the section will be of type SHT_NOTE, if the name
starts with “.note”. Otherwise, it will have type SHT_PROGBITS. Can be
specified multiple times to add multiple sections.
For MachO objects, <section> must be formatted as
<segment name>,<section name>.
:::
:::{option} –binary-architecture
:::{option} –disable-deterministic-archives, -U Use real values for UIDs, GIDs and timestamps when updating archive member headers. :::
:::{option} –discard-all, -x Remove most local symbols not referenced by relocations from the output. Different file formats may limit this to a subset of the local symbols. For example, file and section symbols in ELF objects will not be discarded. Additionally, remove all debug sections. :::
:::{option} –dump-section <section> into the file <file>. Can be
specified multiple times to dump multiple sections to different files.
<file> is unrelated to the input and output files provided to
llvm-objcopy and as such the normal copying and editing
operations will still be performed. No operations are performed on the sections
prior to dumping them.
For MachO objects, <section> must be formatted as
<segment name>,<section name>.
:::
:::{option} –enable-deterministic-archives, -D Enable deterministic mode when copying archives, i.e. use 0 for archive member header UIDs, GIDs and timestamp fields. On by default. :::
:::{option} –extract-section <section> into the file <file> as a
seperate object. Can be specified multiple times to extract multiple sections.
<file> is unrelated to the input and output files provided to
llvm-objcopy and as such the normal copying and editing
operations will still be performed. No operations are performed on the sections
prior to dumping them.
:::
:::{option} –globalize-symbol <symbol> as global symbols in the output.
Can be specified multiple times to mark multiple symbols.
:::
:::{option} –globalize-symbols <filename> and mark defined symbols with
those names as global in the output. In the file, each line represents a single
symbol, with leading and trailing whitespace ignored, as is anything following
a ‘#’. Can be specified multiple times to read names from multiple files.
:::
:::{option} –help, -h Print a summary of command line options. :::
:::{option} –keep-global-symbol <symbol>. Can be specified multiple times to ignore multiple symbols.
:::
:::{option} –keep-global-symbols <filename>. In the file, each line represents a single symbol, with leading
and trailing whitespace ignored, as is anything following a ‘#’. Can be
specified multiple times to read names from multiple files.
:::
:::{option} –localize-symbol <symbol> as a local symbol in the
output. Can be specified multiple times to mark multiple symbols as local.
:::
:::{option} –localize-symbols <filename> and mark defined non-common
symbols with those names as local in the output. In the file, each line
represents a single symbol, with leading and trailing whitespace ignored, as is
anything following a ‘#’. Can be specified multiple times to read names from
multiple files.
:::
:::{option} –only-keep-debug Produce a debug file as the output that only preserves contents of sections useful for debugging purposes.
For ELF objects, this removes the contents of SHF_ALLOC sections that are not
SHT_NOTE by making them SHT_NOBITS and shrinking the program headers where
possible.
:::
:::{option} –only-section <section>.
Can be specified multiple times to keep multiple sections.
For MachO objects, <section> must be formatted as
<segment name>,<section name>.
:::
:::{option} –redefine-sym <old> to <new> in the output. Can be specified
multiple times to rename multiple symbols.
:::
:::{option} –redefine-syms <filename>. In the
file, each line represents a single symbol to rename, with the old name and new
name separated by whitespace. Leading and trailing whitespace is ignored, as is
anything following a ‘#’. Can be specified multiple times to read names from
multiple files.
:::
:::{option} –regex If specified, symbol and section names specified by other switches are treated as extended POSIX regular expression patterns. :::
:::{option} –remove-symbol-prefix <prefix> from the start of every symbol name. No-op for symbols that do
not start with <prefix>.
:::
:::{option} –remove-section
For MachO objects, <section> must be formatted as
<segment name>,<section name>.
:::
:::{option} –set-section-alignment <section> to <align>. Can be specified
multiple times to update multiple sections.
:::
:::{option} –set-section-flags <section> based on the
specified <flag> values. Can be specified multiple times to update multiple
sections.
Supported flag names are alloc, load, noload, readonly, exclude,
debug, code, data, rom, share, contents, merge, strings, and
large. Not all flags are meaningful for all object file formats or target
architectures.
For ELF objects, the flags have the following effects:
alloc= add theSHF_ALLOCflag.load= if the section hasSHT_NOBITStype, mark it as aSHT_PROGBITSsection.readonly= if this flag is not specified, add theSHF_WRITEflag.exclude= add theSHF_EXCLUDEflag.code= add theSHF_EXECINSTRflag.merge= add theSHF_MERGEflag.strings= add theSHF_STRINGSflag.contents= if the section hasSHT_NOBITStype, mark it as aSHT_PROGBITSsection.large= add theSHF_X86_64_LARGEon x86_64; rejected if the target architecture is not x86_64.
For COFF objects, the flags have the following effects:
alloc= add theIMAGE_SCN_CNT_UNINITIALIZED_DATAandIMAGE_SCN_MEM_READflags, unless theloadflag is specified.noload= add theIMAGE_SCN_LNK_REMOVEandIMAGE_SCN_MEM_READflags.readonly= if this flag is not specified, add theIMAGE_SCN_MEM_WRITEflag.exclude= add theIMAGE_SCN_LNK_REMOVEandIMAGE_SCN_MEM_READflags.debug= add theIMAGE_SCN_CNT_INITIALIZED_DATA,IMAGE_SCN_MEM_DISCARDABLEandIMAGE_SCN_MEM_READflags.code= add theIMAGE_SCN_CNT_CODE,IMAGE_SCN_MEM_EXECUTEandIMAGE_SCN_MEM_READflags.data= add theIMAGE_SCN_CNT_INITIALIZED_DATAandIMAGE_SCN_MEM_READflags.share= add theIMAGE_SCN_MEM_SHAREDandIMAGE_SCN_MEM_READflags. :::
:::{option} –skip-symbol <symbol> when executing other
options that can change the symbol’s name, binding or visibility.
:::
:::{option} –skip-symbols <filename> when
executing other options that can change the symbol’s name, binding or
visibility. In the file, each line represents a single symbol, with leading
and trailing whitespace ignored, as is anything following a ‘#’.
Can be specified multiple times to read names from multiple files.
:::
:::{option} –strip-all-gnu
Remove all symbols, debug sections and relocations from the output. This option
is equivalent to GNU objcopy’s --strip-all switch.
:::
:::{option} –strip-all, -S For ELF objects, remove from the output all symbols and non-alloc sections not within segments, except for .gnu.warning, .ARM.attribute sections and the section name table.
For COFF and Mach-O objects, remove all symbols, debug sections, and relocations from the output.
For WebAssembly objects, remove all custom sections except for those named metadata.code.*. :::
:::{option} –strip-debug, -g Remove all debug sections from the output. :::
:::{option} –strip-symbol <symbol> from the output. Can be specified
multiple times to remove multiple symbols.
:::
:::{option} –strip-symbols <filename>, from the
output. In the file, each line represents a single symbol name, with leading
and trailing whitespace ignored, as is anything following a ‘#’. Can be
specified multiple times to read names from multiple files.
:::
:::{option} –strip-unneeded-symbol <symbol> that are local or
undefined and are not required by any relocation.
:::
:::{option} –strip-unneeded-symbols <filename>, from the
output, if they are local or undefined and are not required by any relocation.
In the file, each line represents a single symbol name, with leading and
trailing whitespace ignored, as is anything following a ‘#’. Can be specified
multiple times to read names from multiple files.
:::
:::{option} –strip-unneeded Remove from the output all local or undefined symbols that are not required by relocations. Also remove all debug sections. :::
:::{option} –update-section <name> with contents from the file
<file>. If the section <name> is part of a segment, the new contents
cannot be larger than the existing section.
:::
:::{option} –verbose, -v Print the paths of files that are copied. :::
:::{option} –version, -V Display the version of the llvm-objcopy executable. :::
:::{option} –wildcard, -w Allow wildcard syntax for symbol-related flags. On by default for section-related flags. Incompatible with –regex.
Wildcard syntax allows the following special symbols:
Character |
Meaning |
Equivalent |
|---|---|---|
|
Any number of characters |
|
|
Any single character |
|
|
Escape the next character |
|
|
Character class |
|
|
Negated character class |
|
Additionally, starting a wildcard with ‘!’ will prevent a match, even if
another flag matches. For example -w -N '*' -N '!x' will strip all symbols
except for x.
The order of wildcards does not matter. For example, -w -N '*' -N '!x' is
the same as -w -N '!x' -N '*'.
:::
:::{option} @<FILE>.
:::
ELF-SPECIFIC OPTIONS¶
The following options are implemented only for ELF objects. If used with other objects, llvm-objcopy will either emit an error or silently ignore them.
:::{option} –add-symbol <name> to the output symbol table, in the section
named <section>, with value <value>. If <section> is not specified,
the symbol is added as an absolute symbol. The <flags> affect the symbol
properties. Accepted values are:
global= the symbol will have global binding.local= the symbol will have local binding.weak= the symbol will have weak binding.default= the symbol will have default visibility.hidden= the symbol will have hidden visibility.protected= the symbol will have protected visibility.file= the symbol will be anSTT_FILEsymbol.section= the symbol will be anSTT_SECTIONsymbol.object= the symbol will be anSTT_OBJECTsymbol.function= the symbol will be anSTT_FUNCsymbol.indirect-function= the symbol will be anSTT_GNU_IFUNCsymbol.
Additionally, the following flags are accepted but ignored: debug,
constructor, warning, indirect, synthetic, unique-object, before.
Can be specified multiple times to add multiple symbols. :::
:::{option} –allow-broken-links Allow llvm-objcopy to remove sections even if it would leave invalid section references. Any invalid sh_link fields will be set to zero. :::
:::{option} –change-section-lma *{+-}<val>.
:::
:::{option} –change-section-address <section> pattern to the
specified value, or apply +<val>/-<val> to the current value. Can be
specified multiple times to specify multiple patterns. Each section is only
modified by one --change-section-address argument. If a section name
matches multiple patterns, the rightmost change applies. The object file needs
to be of ET_REL type.
:::
:::{option} –change-start <incr> to the program’s start address. Can be specified multiple
times, in which case the values will be applied cumulatively.
:::
:::{option} –compress-debug-sections [zlib and zstd. Use zlib if <format> is omitted.
:::
:::{option} –compress-sections <section> using the specified
format. Supported formats are zlib and zstd. Specify none for
decompression. When a section is matched by multiple options, the last one
wins. A wildcard <section> starting with ‘!’ is disallowed.
Sections within a segment cannot be (de)compressed.
:::
:::{option} –decompress-debug-sections Decompress any compressed DWARF debug sections in the output. :::
:::{option} –discard-locals, -X Remove local symbols starting with “.L” not referenced by relocations from the output. :::
:::{option} –extract-dwo Remove all sections that are not DWARF .dwo sections from the output. :::
:::{option} –extract-main-partition Extract the main partition from the output. :::
:::{option} –extract-partition
:::{option} –gap-fill <value> instead
of zero. The value must be an unsigned 8-bit integer.
:::
:::{option} –input-target <format> values. If unspecified, llvm-objcopy will attempt
to determine the format automatically.
:::
:::{option} –keep-file-symbols
Keep symbols of type STT_FILE, even if they would otherwise be stripped.
:::
:::{option} –keep-section <section>. Can be specified multiple times to keep multiple sections.
:::
:::{option} –keep-symbol <symbol>. Can be specified multiple times to keep multiple symbols.
:::
:::{option} –keep-symbols <filename>. In the file, each line represents a single symbol, with leading
and trailing whitespace ignored, as is anything following a ‘#’. Can be
specified multiple times to read names from multiple files.
:::
:::{option} –localize-hidden Mark all symbols with hidden or internal visibility local in the output. :::
:::{option} –new-symbol-visibility --add-symbol. Valid options are:
defaulthiddeninternalprotected
The default is default.
:::
:::{option} –no-verify-note-sections When adding note sections, do not verify if the section format is valid. :::
:::{option} –output-target <format> values. If unspecified, the output format is assumed to
be the same as the value specified for --input-target or the input
file’s format if that option is also unspecified.
:::
:::{option} –pad-to
For binary outputs, pad the output to the load address<address> using a value
of zero or the value specified by --gap-fill.
:::
:::{option} –prefix-alloc-sections <prefix> to the front of the names of all allocatable sections in the
output.
:::
:::{option} –prefix-symbols <prefix> to the front of every symbol name in the output.
:::
:::{option} –preserve-dates, -p Preserve access and modification timestamps in the output. :::
:::{option} –remove-note [<type> and name <name> from SHT_NOTE
sections that are not in a segment. Can be specified multiple times.
:::
:::{option} –rename-section <old> to <new> in the output, and apply any
specified <flag> values. See --set-section-flags for a list of
supported flags. Can be specified multiple times to rename multiple sections.
:::
:::{option} –set-section-type <section> to the integer <type>. Can be
specified multiple times to update multiple sections.
:::
:::{option} –set-start <addr>. Overrides any previously
specified --change-start or --adjust-start options.
:::
:::{option} –set-symbol-visibility
:::{option} –set-symbols-visibility
:::{option} –split-dwo --extract-dwo and
<dwo-file> as the output file and no other options, and then with
--strip-dwo on the input file.
:::
:::{option} –strip-dwo Remove all DWARF .dwo sections from the output. :::
:::{option} –strip-non-alloc Remove from the output all non-allocatable sections that are not within segments. :::
:::{option} –strip-sections Remove from the output all section headers and all section data not within segments. Note that many tools will not be able to use an object without section headers. :::
:::{option} –target --input-target and --output-target for the
specified format. See [SUPPORTED FORMATS] for a list of valid <format>
values.
:::
:::{option} –verify-note-sections When adding note sections, verify if the section format is valid. On by default. :::
:::{option} –weaken-symbol <symbol> as weak symbols in the output. Can
be specified multiple times to mark multiple symbols as weak.
:::
:::{option} –weaken-symbols <filename> and mark global symbols with
those names as weak in the output. In the file, each line represents a single
symbol, with leading and trailing whitespace ignored, as is anything following
a ‘#’. Can be specified multiple times to read names from multiple files.
:::
:::{option} –weaken Mark all defined global symbols as weak in the output. :::
MACH-O-SPECIFIC OPTIONS¶
:::{option} –keep-undefined Keep undefined symbols, even if they would otherwise be stripped. :::
COFF-SPECIFIC OPTIONS¶
:::{option} –subsystem
SUPPORTED FORMATS¶
The following values are currently supported by llvm-objcopy for the
--input-target, --output-target, and --target
options. For GNU objcopy compatibility, the values are all bfdnames.
binaryihexelf32-i386elf32-x86-64elf64-x86-64elf32-iamcuelf32-littlearmelf64-aarch64elf64-littleaarch64elf32-littleriscvelf64-littleriscvelf32-powerpcelf32-powerpcleelf64-powerpcelf64-powerpcleelf32-bigmipself32-ntradbigmipself32-ntradlittlemipself32-tradbigmipself32-tradlittlemipself64-tradbigmipself64-tradlittlemipself32-sparcelf32-sparcelelf32-hexagonelf32-loongarchelf64-loongarchelf64-s390elf64-amdgpu
The following formats are supported by llvm-objcopy for the
--output-target only:
srec
Additionally, all targets except binary, ihex, and srec can have
-freebsd as a suffix.
BINARY INPUT AND OUTPUT¶
If binary is used as the value for --input-target, the input file
will be embedded as a data section in an ELF relocatable object, with symbols
_binary_<file_name>_start, _binary_<file_name>_end, and
_binary_<file_name>_size representing the start, end and size of the data,
where <file_name> is the path of the input file as specified on the command
line with non-alphanumeric characters converted to _.
If binary is used as the value for --output-target, the output file
will be a raw binary file, containing the memory image of the input file.
Symbols and relocation information will be discarded. The image will start at
the address of the first loadable section in the output.
EXIT STATUS¶
llvm-objcopy exits with a non-zero exit code if there is an error. Otherwise, it exits with code 0.
BUGS¶
To report bugs, please visit <https://github.com/llvm/llvm-project/labels/tools:llvm-objcopy/strip/>.
There is a known issue with --input-target and --target
causing only binary and ihex formats to have any effect. Other values
will be ignored and llvm-objcopy will attempt to guess the input
format.
