llvm-objcopy - object copying and editing tool#
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.
- --add-gnu-debuglink <debug-file>#
Add a .gnu_debuglink section for
<debug-file>to the output.
- --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 typeSHT_NOTE, if the name starts with “.note”. Otherwise, it will have typeSHT_PROGBITS. Can be specified multiple times to add multiple sections.For MachO objects,
<section>must be formatted as<segment name>,<section name>.
- --binary-architecture <arch>, -B#
Ignored for compatibility.
- --disable-deterministic-archives, -U#
Use real values for UIDs, GIDs and timestamps when updating archive member headers.
- --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.
- --dump-section <section>=<file>#
Dump the contents of 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>.
- --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.
- --extract-section <section>=<file>#
Extract the specified 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.
- --globalize-symbol <symbol>#
Mark any defined symbols named
<symbol>as global symbols in the output. Can be specified multiple times to mark multiple symbols.
- --globalize-symbols <filename>#
Read a list of names from the file
<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.
- --help, -h#
Print a summary of command line options.
- --keep-global-symbol <symbol>, -G#
Mark all symbols local in the output, except for symbols with the name
<symbol>. Can be specified multiple times to ignore multiple symbols.
- --keep-global-symbols <filename>#
Mark all symbols local in the output, except for symbols named in the file
<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.
- --localize-symbol <symbol>, -L#
Mark any defined non-common symbol named
<symbol>as a local symbol in the output. Can be specified multiple times to mark multiple symbols as local.
- --localize-symbols <filename>#
Read a list of names from the file
<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.
- --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_ALLOCsections that are notSHT_NOTEby making themSHT_NOBITSand shrinking the program headers where possible.
- --only-section <section>, -j#
Remove all sections from the output, except for sections named
<section>. Can be specified multiple times to keep multiple sections.For MachO objects,
<section>must be formatted as<segment name>,<section name>.
- --redefine-sym <old>=<new>#
Rename symbols called
<old>to<new>in the output. Can be specified multiple times to rename multiple symbols.
- --redefine-syms <filename>#
Rename symbols in the output as described in the file
<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.
- --regex#
If specified, symbol and section names specified by other switches are treated as extended POSIX regular expression patterns.
- --remove-symbol-prefix <prefix>#
Remove
<prefix>from the start of every symbol name. No-op for symbols that do not start with<prefix>.
- --remove-section <section>, -R#
Remove the specified section from the output. Can be specified multiple times to remove multiple sections simultaneously.
For MachO objects,
<section>must be formatted as<segment name>,<section name>.
- --set-section-alignment <section>=<align>#
Set the alignment of section
<section>to<align>. Can be specified multiple times to update multiple sections.
- --set-section-flags <section>=<flag>[,<flag>,...]#
Set section properties in the output of section
<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, andlarge. 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.
- --skip-symbol <symbol>#
Do not change the parameters of symbol
<symbol>when executing other options that can change the symbol’s name, binding or visibility.
- --skip-symbols <filename>#
Do not change the parameters of symbols named in the file
<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.
- --strip-all-gnu#
Remove all symbols, debug sections and relocations from the output. This option is equivalent to GNU objcopy’s
--strip-allswitch.
- --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.*.
- --strip-debug, -g#
Remove all debug sections from the output.
- --strip-symbol <symbol>, -N#
Remove all symbols named
<symbol>from the output. Can be specified multiple times to remove multiple symbols.
- --strip-symbols <filename>#
Remove all symbols whose names appear in the file
<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.
- --strip-unneeded-symbol <symbol>#
Remove from the output all symbols named
<symbol>that are local or undefined and are not required by any relocation.
- --strip-unneeded-symbols <filename>#
Remove all symbols whose names appear in the file
<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.
- --strip-unneeded#
Remove from the output all local or undefined symbols that are not required by relocations. Also remove all debug sections.
- --update-section <name>=<file>#
Replace the contents of the 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.
- --verbose, -v#
Print the paths of files that are copied.
- --version, -V#
Display the version of the llvm-objcopy executable.
- --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
\[a-z]Character class